$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>woocommerce offtopic - Correct method of reducing the number of images created by WP and Woo together|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin8PV0评论

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;

Post a comment

comment list (0)

  1. No comments so far