woocommerce offtopic - Correct method of reducing the number of images created by WP and Woo together

admin2025-06-03  7

I create my own WP&Woo theme and i have some doubts about the number of images that are generated by wordpress plus woocommerce

  • Wordpress generate 4 sizes
  • Woocommerce generate another 3 sizes

So we have 7 generated images

Its not hard to count that if we have a eight thounsand products, WP and Woo will generate 56 thousands images!!! In my opinion it's a little disaster

I looking for a best solution for decrease that

My 1st idea:

Unset WP default images sizes with intermediate_image_sizes_advanced filter. I think it's not a best idea to remove default sizes. Example below:

function remove_default_images_size( $sizes ) {

    unset( $sizes['thumbnail']); 
    unset( $sizes['medium']); 
    unset( $sizes['medium_large']); // special hidden size
    unset( $sizes['large']);

    return $sizes;

} add_filter( 'intermediate_image_sizes_advanced' , 'remove_default_images_size' );

or 2nd idea:

Changing images dimensions in Woocommerce to identical with WP. We can do that via hooks. Example for thumbnails below:

add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) {
    return array (
        'width' => 150,
        'height' => 150,
        'crop' => 1
    );
} );

If i will do that,additional Woo images will not created because they will had the same sizes like WP native images.

All above method works, but my question is:

  • which method will be better and more logical for project future?
  • maybe is another method that i don't know?
  • or maybe I should leave it as it is?

I create my own WP&Woo theme and i have some doubts about the number of images that are generated by wordpress plus woocommerce

  • Wordpress generate 4 sizes
  • Woocommerce generate another 3 sizes

So we have 7 generated images

Its not hard to count that if we have a eight thounsand products, WP and Woo will generate 56 thousands images!!! In my opinion it's a little disaster

I looking for a best solution for decrease that

My 1st idea:

Unset WP default images sizes with intermediate_image_sizes_advanced filter. I think it's not a best idea to remove default sizes. Example below:

function remove_default_images_size( $sizes ) {

    unset( $sizes['thumbnail']); 
    unset( $sizes['medium']); 
    unset( $sizes['medium_large']); // special hidden size
    unset( $sizes['large']);

    return $sizes;

} add_filter( 'intermediate_image_sizes_advanced' , 'remove_default_images_size' );

or 2nd idea:

Changing images dimensions in Woocommerce to identical with WP. We can do that via hooks. Example for thumbnails below:

add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) {
    return array (
        'width' => 150,
        'height' => 150,
        'crop' => 1
    );
} );

If i will do that,additional Woo images will not created because they will had the same sizes like WP native images.

All above method works, but my question is:

  • which method will be better and more logical for project future?
  • maybe is another method that i don't know?
  • or maybe I should leave it as it is?
Share Improve this question edited Feb 8, 2019 at 14:29 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Feb 8, 2019 at 13:27 kanlukaszkanlukasz 5448 silver badges24 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I would remove the image sizes that you don't need.

function remove_image_sizes() {
    remove_image_size('image-name');
}
add_action('init', 'remove_image_sizes', 99);

Whilst the number of images is a factor, I'd also look at the image compression as this may be a big help in reducing the disk space required:

add_filter('jpeg_quality', function($arg){return 70;});

You will need to re-generate your images for this to take effect. Try the Regenerate Thumbnails plugin. Alternatively, you can run a command line like convert.

Here's a guide: https://www.howtogeek/109369/how-to-quickly-resize-convert-modify-images-from-the-linux-terminal/

One final method to remove the Wordpress default images is to set the dimensions to 0, as per this article;

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748931228a314921.html

最新回复(0)