WordPress Tip: Change default thumbnail size for Featured Image

Here’s a quick little tip that took me a long time to figure out.

Within WordPress, multiple sizes of images can be created when a photo is uploaded, such as thumbnail, medium and large. This is controlled in the Settings/Media. However, none of these settings control the size of the thumbnail for a Featured Image. This is actually defined in the functions.php file of your theme.

When customizing themes, it is generally recommended to create a child theme and then make any modifications there. Please click here for more information. Once you have a child theme setup, you’ll want to create a new functions.php file in the Child Theme’s folder on your server. By adding the following code to this file, you’ll be able to control the size of your Featured Image thumbnails.

if ( ! function_exists( 'child_theme_setup' ) ):
    function child_theme_setup() {
        if ( function_exists( 'add_theme_support' ) ) {
            add_theme_support( 'post-thumbnails' );
            set_post_thumbnail_size( 150, 150, false );
        }
    }
endif;

add_action( 'after_setup_theme', 'child_theme_setup', 11 );

The key line is:

set_post_thumbnail_size( 150, 150, false );

The three arguments control the maximum width, maximum height, and crop respectively. If crop is set to true, then the image will be cropped at these dimensions and may change the aspect ratio of the image. If set to false, then the aspect ratio will remain with the longest dimension matching your maximum setting.

The other key line is the last one:

add_action( 'after_setup_theme', 'child_theme_setup', 11 );

Child themes are setup so that any functions in this functions.php file are run before the parent theme’s functions.php file. But with this line, we are changing the priority so that the function, child_them_setup in this case, is called after any functions in the parent theme. As a result, the default settings for set_post_thumbnail_size will be overridden.