WordPress – add_theme_support(‘post-thumbnails’) how to add size into function?

I really want to keep my code lean, and i’am wondering what is the best way write this code.

Can i include my add_image_size function into my add_theme_support(‘post-thumbnails’);, and how would i go about it?

Read More

i want to add the images_size attributes into post-thumbnails function.

if ( ! function_exists( 'RJK_setup' ) ) :
function RJK_setup() {
load_theme_textdomain( 'RJK', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
add_theme_support('post-thumbnails');

register_nav_menus( array(
    'primary' => __( 'Primary Menu', 'RJK' ),
) );

add_theme_support( 'html5', array(
    'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
) );

add_theme_support( 'post-formats', array(
    'aside', 'image', 'video', 'quote', 'link'
) );

add_theme_support( 'custom-background', apply_filters( 'RJK_custom_background_args',      array(
    'default-color' => 'ffffff',
    'default-image' => '',
) ) );
}endif; // RJK_setup
add_action( 'after_setup_theme', 'RJK_setup' );

.

if ( function_exists('add_image_size') ) {
add_image_size('tiny', 128, 79);
add_image_size('small', 256, 158);
add_image_size('medium', 384, 237);
add_image_size('large', 512, 316);
};

i hope its clear what i mean.

Related posts

Leave a Reply

1 comment

  1. There’s no other way.
    You have to do exactly what you’re doing.

    You have to enable post thumbnails with add_theme_support( 'post-thumbnails' ) the onle args you can pass is an array with the post types you wanna enable post thumbnails add_theme_support( 'post-thumbnails', array( 'post' ) ); this will enable Post Thumbnails only for Posts post type.

    And to create image sizes you have to use add_image_size( $name, $width, $height, $crop );

    if ( ! function_exists( 'RJK_setup' ) ) :
    
        function RJK_setup() {
    
            add_theme_support('post-thumbnails');
    
            if ( function_exists('add_image_size') ) {
                add_image_size('tiny', 128, 79);
                add_image_size('small', 256, 158);
                add_image_size('medium', 384, 237);
                add_image_size('large', 512, 316);
            };
        }
    
    
    endif;
    add_action( 'after_setup_theme', 'RJK_setup' );