WordPress Featured Images – add_image_size() resizing and cropping

This post is in response to a question that has cropped up a couple of times in the Comments of my WordPress Featured Images – add_image_size() resizing and cropping demo article.

The question? How to stop WordPress from creating default image sizes namely, the thumbnail, or medium, or large image sizes?

Not quite sure what we are talking about? For everything you ever wanted to know about WordPress image handling (but were afraid to ask), please refer to my WordPress Featured Images – add_image_size() resizing and cropping demo article.

Back to our question… Although it is possible to prevent the creation of default image sizes by changing their dimension settings to ’0′ in Dashboard > Settings > Media, these image sizes will still appear in the list of sizes in the Media Uploader. Luckily, after trawling through WordPress core files, I found a filter that we can hook into to stop any or all of these default image sizes from being created during the upload process and from being listed in the Media Uploader.

Add the below code to your theme’s functions.php:

 

/*-----------------------------------------------------------------------------------*/
/* Images
/*-----------------------------------------------------------------------------------*/
if ( function_exists( 'add_theme_support' ))
add_theme_support( 'post-thumbnails' );

if ( function_exists( ‘add_image_size’ ) ) {
//add_image_size( ‘full-size’, 9999, 9999, false );
//add_image_size( ‘small-thumb’, 54, 54, true );
add_image_size( ‘slider’, 970, 9999, false );
//add_image_size( ‘post-image’, 660, 220, true );
add_image_size( ‘blog-thumb’, 280, 92, true );
//add_image_size( ‘grid-thumb’, 215, 140, true );
//add_image_size( ‘gallery-thumb’, 205, 140, true );
//add_image_size( ‘staff-thumb’, 100, 100, true );
//add_image_size( ‘portfolio-single’, 500, 9999, false );
}

In the above example, I am removing ALL default image sizes. If you don’t want to remove all the default sizes, just remove the relevant unset() lines for those default sizes that you wish to keep.

Add Comment