Removing Standard Image Sizes from WordPress

I ran across an issue today where I needed to specify which image sizes were generated within WordPress. I didn’t need the stock sizes (thumbnail, medium, large) but I did need a few custom sizes. Adding custom sizes is the easy part but removing others threw me for a loop.

The quick and dirty solution would be to set the sizes in Settings > Media to 0 so that nothing would be generated. While this works on a single site, its not the best solution for something that would be deployed on multiple sites. After all, who wants to remember to change individual settings on each new site?

Best solution, filtering intermediate_image_sizes. Basically all you need to do is return an array of what sizes you want generated. In the example below, I had already used add_image_size() to generate 3 new sizes: theme-small, theme-medium, and theme-large.

Here’s the code:

add_filter( 'intermediate_image_sizes', 'rcd_remove_stock_image_sizes' );

function rcd_remove_stock_image_sizes( $sizes ) {
    return array( 'theme-small', 'theme-medium', 'theme-large' );
}

Basically what this does is define only our 3 new image sizes in the array eliminating the stock sizes of thumbnail, medium, and large.

Thanks to @Otto42 for the tip!