[00] Subset Sizes, User guide
Stop WordPress generating image sizes
Last updated
Filter the sizes WordPress makes at upload with a code snippet, or let Subset Sizes create each size the first time a page asks for it.
To stop WordPress generating image sizes at upload, remove them with the intermediate_image_sizes_advanced filter, or install Subset Sizes and turn on Lazy sizes so each size is made the first time a page asks for it. The filter stops the files being made, but a page that later asks for a removed size gets the full image instead. On-demand sizes keep uploads small and still give every page the size it asked for.
Why one upload becomes several files
When you upload a JPEG, WordPress saves the original, then makes a resized copy for every registered size. Sizes come from three places:
- WordPress core registers six:
thumbnail(150 pixels),medium(300),medium_large(768),large(1024),1536x1536and2048x2048. - Your theme registers its own with
add_image_size(). - Plugins do the same. WooCommerce adds sizes for product images, for example.
Large uploads get one more file. If the original is wider or taller than 2560 pixels, WordPress saves a copy scaled down to fit 2560 pixels, adds -scaled to its file name, and shows that copy as the full-size image. The original stays on disk next to it.
On a test site with only the six core sizes, one 4000 × 3000 pixel JPEG became 8 files: the original, the -scaled copy and six sizes. Every size a theme or plugin registers adds another file to every upload.
What the extra files cost
Each file uses disk space and an inode, and many hosts cap the number of inodes on a plan. Backups and migrations copy every one of them. Uploads also take longer, because WordPress resizes the image once per size before the upload finishes.
Many of those files are never shown. A theme you switched away from leaves its sizes behind, and a photo that only ever appears as a thumbnail still gets a 2048-pixel copy.
Stop sizes with a code snippet
WordPress has two filters for this. Put them in a small plugin or your theme’s functions.php.
intermediate_image_sizes_advanced gets the sizes WordPress is about to make for an upload, keyed by size name. Remove the ones you don’t want:
<?php
add_filter(
'intermediate_image_sizes_advanced',
function ( array $sizes ): array {
unset( $sizes['medium_large'], $sizes['1536x1536'], $sizes['2048x2048'] );
return $sizes;
}
);
big_image_size_threshold sets the 2560-pixel limit. Return false and WordPress stops making the -scaled copy:
<?php
add_filter( 'big_image_size_threshold', '__return_false' );
Check the trade-offs before you rely on them:
- Both filters only change new uploads. Files already in your uploads folder stay.
- A size you remove never exists for that image. When a theme asks for it by name, WordPress falls back to the full-size image, so a 300-pixel slot can load the 2560-pixel
-scaledfile. - Responsive
srcsetattributes only list sizes in the image’s metadata, so the browser has fewer sizes to choose from. - With the threshold turned off, the full-size image on your pages is the original upload, 4000 pixels wide in the example above.
Create sizes on demand instead
Subset Sizes keeps every registered size available but only makes a file when something asks for it. With Lazy sizes on, an upload creates only the sizes ticked under Create at upload, which are thumbnail and medium by default. On a new install, Lazy sizes is already on. You can check it, and change which sizes are made at upload, on Subset → Image Sizes.
It uses the same intermediate_image_sizes_advanced filter to skip sizes at upload. The difference is what happens afterwards:
- When a theme asks for a size that hasn’t been made, it gets that size’s URL, not the full-size image.
srcsetattributes list every matching size, whether its file exists yet or not.- When a browser requests a size file that doesn’t exist, such as
photo-1024x768.jpg, the plugin makes it from the original and saves it. From then on your web server serves the file directly.
With Lazy sizes on, the same 4000 × 3000 pixel JPEG became 4 files: the original, the -scaled copy, thumbnail and medium. WordPress resized it twice at upload instead of six times, and the other four sizes are made only if a page shows them.
Subset Sizes doesn’t change the -scaled copy. If you don’t want it, the big_image_size_threshold snippet above still applies.
On-demand sizes need the request for a missing file to reach WordPress. Apache with pretty permalinks needs nothing else, and nginx needs one rule. Both are in Getting started.
Remove sizes you already have
The filters and Lazy sizes only change what happens at upload. To delete files left behind by sizes nothing registers any more, such as an old theme’s, preview the list first and then run it:
wp subset image-resizer clean-orphans --dry-run
wp subset image-resizer clean-orphans
It never touches originals, -scaled copies or image editor backups. A size that’s requested again later is made on demand, so deleting size files doesn’t leave broken images. To see how many size files you have and how much space they use, run wp subset image-resizer stats.
For sizes that are still registered but unused, Subset Sizes Pro’s Audit tab records which sizes your pages load and deletes the files of sizes nobody has used for 30 days. On-demand and lazy sizes covers both.