When I add a new product photo in the WooCommerce list, it creates a lot of different photos in different sizes such as xproduct.png, xproduct-80×80.png, xproduct-480×480.png, xproduct-720×720.png, etc.
I don’t know where is the core of this problem. Do I have problems with WordPress or WooCommerce?
How can I fix this? My database is full of these unnecessary photos.
For example;
I have 100 products with 10 photos for each, but it creates 10 different photos for each photo, and finally, I have 100 photos for just one product. It means that I have 1,000 photos for 100 products.
2
Answers
WordPress generates 3 image sizes by default (‘thumbnail’, ‘medium’, ‘large’) and keeps the original one (‘full’).
But any theme or plugin can register its own sizes for different purposes. New sizes are typically added with
add_image_size()
core function.If your theme/plugins generate excessive image sizes, you can remove unnecessary rather easily.
get_intermediate_image_sizes()
.remove_image_size()
function to override the registration of unused sizes. You should call it right in time (after the registration. but before any output starts), so you’ll probably call a hook.This example removes all image sizes except the allowed ones:
Then you might want to run some cleaner plugins (e.g. Media Cleaner) to remove existing unused files and database records.
Asthis discussed in other stack threads the reason is due to a certain plugin or current theme creating those image sizes. Each image size generates an image of that particular dimension. You need to find out which plugin or theme is doing so. Mostly, theme cause this. Look in your theme’s function.php or plugin files and find function calls like this:-
Remove the add_image_size function calls to avoid generating multiple sizes of the image.
http://codex.wordpress.org/Function_Reference/add_image_size