This website uses cookies to allow us to see how the site is used. If you continue to use this site, we assume that you are okay with this. If you want to use the sites without cookies, please see our privacy policy.

How to Disable All Unwanted Image Sizes

This year, give your site the gift that keeps on giving: better optimized image handling. As of version 5.3, WordPress automatically generates seven (7!) additional images for every image that you upload via the WP Media Library (and/or RTE/Visual editor). So in addition to the original image on the server, WordPress generates images with the following dimensions:

Image Size Dimensions
Thumbnail (Size based on Media settings)
Medium (Size based on Media settings)
Large (Size based on Media settings)
Medium Large 768px
2x Medium Large 1536px
2x Large 2048px
Scaled 2560px

Here is an example of what all those extra images look like on the server. By default, for each and every uploaded image you get this:

What does this mean for you and your website? It means that all those extra images are eating up precious server space and resources. If you make use of all the alternate images, then great; stop reading here and go enjoy the holidays. Otherwise, you may want to optimize WordPress default image handling and disable any unwanted image sizes. You know, to save disk space and keep your site running lean, mean, and wonderful.

How to disable unwanted image sizes

Fortunately, WordPress provides a way to do almost anything, including disabling all of the extra image sizes. So for this year’s “Snippets til Christmas” post, I’m going to share the magic recipe to give you full control over all WordPress generated images. Ready? Here goes:

// disable generated image sizes
function shapeSpace_disable_image_sizes($sizes) {
    unset($sizes['thumbnail']); // disable thumbnail size 
    unset($sizes['medium']); // disable medium size 
    unset($sizes['large']); // disable large size 
    unset($sizes['medium_large']); // disable medium-large size 
    unset($sizes['1536x1536']); // disable 2x medium-large size 
    unset($sizes['2048x2048']); // disable 2x large size return $sizes;
}
add_action('intermediate_image_sizes_advanced', 'shapeSpace_disable_image_sizes');

That takes care of all but the “Scaled” image size, which can be handled by adding the following line:

// disable scaled image size
add_filter('big_image_size_threshold', '__return_false');

Add those two code snippets to your theme’s functions.php file and done. Once added, the code tells WordPress to NOT generate any extra images. So only the original uploaded image will be added to the server. And if you want to keep some of the generated image sizes, you can simply remove the corresponding line from the function. For example, if I want WordPress to generate only the image sizes that are specified in the Media Settings (in the Admin Area), the above code could be modified like so:

// disable generated image sizes
function shapeSpace_disable_image_sizes($sizes) { 
    unset($sizes['medium_large']); // disable medium-large size 
    unset($sizes['1536x1536']); // disable 2x medium-large size 
    unset($sizes['2048x2048']); // disable 2x large size return $sizes;
}
add_action('intermediate_image_sizes_advanced', 'shapeSpace_disable_image_sizes'); // disable scaled image size add_filter('big_image_size_threshold', '__return_false');

And so forth, you can dial in the perfect configuration and optimize your site’s image handling and server resources. Merry Christmas 🙂

Going further..

While the above technique is great for disabling any/all of the default generated image sizes, it’s still possible that your theme or some plugin is creating even more sizes. To learn more about this and how to disable any extra theme or plugin-related images, check out my in-depth tutorial at Perishable Press, How to Disable WordPress Automatically Generated Images – Complete Guide. There you’ll find everything you need to know about WordPress automatically generated images, Post Thumbnail images, important tips, and much more.

About

Jeff Starr is a professional developer, designer, author, editor, publisher, and teacher with nearly 20 years working online, and over 15 years working with WordPress. His books include Digging into WordPress, The Tao of WordPress, .htaccess made easy, and WordPress Themes In Depth. Jeff also writes tutorials on WordPress, web development and security at Perishable Press, DigWP.com, and WP Mix. He runs his own business at Monzilla Media, and develops premium WordPress plugins at Plugin Planet. You can find him on Twitter @perishable.

6 thoughts on “How to Disable All Unwanted Image Sizes

  1. Unfortunately I am still seeing the auto generated images after adding this code. Is there something else I need to do to make it work? Thanks!

    1. I’m not sure what might be happening in your case, but here are some things that may be useful for you:

      The technique only work on images that are uploaded to the Media Library
      The code snippets only work for newly uploaded images (it’s not retro-active)
      You can verify the technique works properly on a default WP install w/ only default plugins and theme
      If the technique is not working on your newly uploaded images, something (like a theme or plugin) is interfering with normal functionality. In which case, the best way to identify the issue is to do some basic troubleshooting. Here is a free troubleshooting guide for WordPress, specifically for this issue check out the sections on “Plugins” and “Themes” should be most useful.

      I hope that helps, also here is a more in-depth tutorial on the topic that provides a lot more details, etc.

  2. Is there a reason for the yellow on light grey text in your code examples? Like, you have Superman vision, unlike we mere mortals?

    Sarcasm aside, great article & snippet; thanks!

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.