Archived topic
Why Wordpress is Generating Additional Image Copies
5 replies · Started by Shubham on September 20, 2020
Recently I noticed that whenever I upload an image into WordPress. WordPress itself creates duplicates copies with different dimensions.
They're just increasing my file count because they're also bigger in size and they are not of any use. How to get rid of that ?
Have a look at my file manager - https://prnt.sc/ukwjuf
Also, see my media settings - https://prnt.sc/ukwkd1
Hi there,
did you make those changes to the Media Attachments before or after you uploaded your images? As that method will ( should ) only apply to new uploads.
these changes I made many months ago.
Recently I noticed that whenever I upload an image into WordPress. WordPress itself creates duplicates copies with different dimensions.
The Media Attachment changes David mentioned are registered image settings.
Whenever you upload an image, WordPress automatically makes images for each registered image sizes.
Since you've mentioned "these changes I made many months ago.", these generated image files from registered image sizes piled up. Also, changing the media settings doesn't image sizes for previously uploaded images.
To address this, we must remove unwanted/unused registered image sizes. To do that, we can use Regenerate Thumbnails plugin or any plugins of similar utility. https://wordpress.org/plugins/regenerate-thumbnails/
This is done so WordPress only generates image sizes that we will actually use.
After doing these, you can use another plugin to clean/remove/delete any unused media files.
you're not getting my point.
I want to stop image generation for future upload.
Suggest me setting by which whenever I upload "Image.PNG" then only one image is uploaded not its other dimensions such as
Image-700x350.PNG
Image-1400x1800.PNG etc
you’re not getting my point.
I want to stop image generation for future upload.
Suggest me setting by which whenever I upload “Image.PNG” then only one
My apologies, I should've been more concise.
That's actually the main reason why I recommended removing unused registered image sizes. Removing unused registered image size is the way to stop WordPress from generating image sizes you don't use when you upload in the future. :D
But we can't unset/remove these unwanted registered image sizes if we don't know the list of which ones to unset/remove.
That's where the plugin comes in.
I recommended a plugin so you get a clear picture of the list of registered image sizes. Regenerate Thumbnail lists that for you.
Regenerate Thumbnail does 2 things for you.
1.) Helps you remove the old images you don't want to use anymore.
2.) It gives you a list of registered image sizes so you know what to unset/remove
Note: It will look something like this https://share.getcloudapp.com/5zuG0l8w
Once we have the list of registered image sizes we want to unset/remove, we can go ahead w/ removing them using PHP snippets. Reminder: we do this so the future uploads don't generate unwanted image sizes anymore.
Here's an example PHP code snippet that removes registered image:
// 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');
// disable scaled image size
add_filter('big_image_size_threshold', '__return_false');
// disable other image sizes
function shapeSpace_disable_other_image_sizes() {
remove_image_size('post-thumbnail'); // disable images added via set_post_thumbnail_size()
remove_image_size('another-size'); // disable any other added image sizes
}
add_action('init', 'shapeSpace_disable_other_image_sizes');
We change the values depending on what we want to remove on the registered image sizes list we find on the site.
Additional notes: You can uninstall the plugin after doing this. Also, if the plugin doesn't do enough job to do #1, there are other plugins can help you clean for unwanted/unused files too. :)
Useful references:
https://developer.wordpress.org/reference/functions/remove_image_size/
https://perishablepress.com/disable-wordpress-generated-images/#solution
https://wpbeaches.com/remove-unused-image-media-sizes-wordpress-theme/