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!

7 Replies to “Removing Standard Image Sizes from WordPress”

  1. Nice tip. Just out of curiosity, though, is there a reason you didn’t simply modify the standard sizes that WordPress creates, instead of removing them and recreating them?

  2. Curt,

    Yes. Sometimes its just not feasible to use the sizes. In this case, I wanted to add custom sizes to a theme where defining it in your functions.php was the best route vs defining / modifying them in wp-admin.

    You can set the thumbnail size via set_post_thumbnail_size() but I’m not aware of a way to easily set the sizes for medium and large images without going to Settings > Media and changing the values there.

    Obviously with a theme you want to reuse in places, you want to define as much as you can with the theme instead of having to hand modify. Simplicity out of the box is always the best option.

    Also re: removing and recreating, what if I had 5 different use cases? I could create 3 via modifying standard ones then having to create 2 additional ones. Streamlining 5 new ones in one place and removing the 3 I don’t need would make the most sense. Thats what filters are for, after all. 😉

  3. So, I used this or a similar function about two years ago (or so). Then couldn’t find the theme/client site I put it in and could never find it again. So, thank you for posting this.

    🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.