How to prevent WordPress from creating thumbnails

WordPress has this great feature to create thumbnails for every media (image) you upload.

This is great as long as you use those thumbnails in your theme. However if you don't those extra images will start using up your space. Imagine 3000 uploads with its own set of thumbnails (x3)... well, you do the math.

Some blog posts will recommend you to set the size of the thumbnails (from Settings > Media) to 0. At the time of the writing (WordPress 3.9) the size 0 trick doesn't work.

You can turn the thumbnails off by pasting this snippet in your theme's functions.php file.

function thumbnail_override($sizes){
    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['large']);

    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'thumbnail_override' );Code language: PHP (php)

Overriding custom size thumbnails

If you're using a Child Theme (and you should) you might want to also remove custom sizes set from the parent theme.

Here's an example to remove TwentyTwelve custom thumbnail size:

function thumbnail_override($sizes){

    unset( $sizes['post-thumbnail']);
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'thumbnail_override', 11 )Code language: PHP (php)

As you can see we've done two things here.

  1. Delay the filter by passing 11 as a parameter.
  2. Unsetting the custom size.

Leave a Reply

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