Reputation: 1471
I have a theme that generates 11 different sized images for every image uploaded.
set_post_thumbnail_size( 220, 150, true);
add_image_size( 'redmag-blog-list', 491, 280, true);
add_image_size( 'redmag-blog-list-large', 614, 320, true);
add_image_size( 'redmag-sidebar', 100 ,100, true);
add_image_size( 'redmag-blog-grid', 496, 290, true);
add_image_size( 'redmag-blog-tran', 480 ,250, true);
add_image_size( 'redmag-blog-tran-vertical', 328 ,480, true);
add_image_size( 'redmag-blog-video',480,150,true);
add_image_size( 'redmag-mini-list', 150 ,100, true);
add_image_size( 'redmag-blog-tran-large', 770 ,420, true);
add_image_size( 'redmag-blog-vertical', 510 ,680, true);
add_image_size( 'redmag-related-image',370,247,true);
This is okay for the theme but it also resizes every image uploaded on Woocommerce which isn't required and takes up a lot of space.
As a temporary measure, I comment out the above code while adding images to woocommerce so it doesn't generate those images.
Can I disable the image generation for ONLY Woocommerce uploaded images?
Upvotes: 2
Views: 1802
Reputation: 1436
Try this:
add_action( 'init', 'custom_remove_image_sizes' );
function custom_remove_image_sizes() {
remove_image_size( '1536x1536' );
remove_image_size( '2048x2048' );
remove_image_size( 'medium_large' );
remove_image_size( 'woocommerce_gallery_thumbnail' );
remove_image_size( 'woocommerce_single' );
remove_image_size( 'woocommerce_thumbnail' );
}
Upvotes: 0
Reputation: 811
As far as I know (not sure if anything has changed) you can't, image sizes are created when you add them via New Media, but I'm leaving that to someone better informed.
You may try some workarounds like the one below tested and working but not checked for conflicts:
// theme image size
add_image_size( '1280', 1280, 9999 );
function mlnc_remove_add_image_sizes() {
// remove theme image size
remove_image_size( '1280' );
// add product image size
add_image_size('1165', 1165, true );
}
if ( get_post_type( $_REQUEST['post_id'] ) === 'product' ) {
add_action('init', 'mlnc_remove_add_image_sizes');
}
This is the basic idea...
Upvotes: 0
Reputation: 4382
You can try code below:
function remove_default_image_sizes( $sizes ) {
/* Default WordPress */
unset( $sizes[ 'thumbnail' ]); // Remove Thumbnail (150 x 150 hard cropped)
unset( $sizes[ 'medium' ]); // Remove Medium resolution (300 x 300 max height 300px)
unset( $sizes[ 'medium_large' ]); // Remove Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
unset( $sizes[ 'large' ]); // Remove Large resolution (1024 x 1024 max height 1024px)
/* With WooCommerce */
unset( $sizes[ 'shop_thumbnail' ]); // Remove Shop thumbnail (180 x 180 hard cropped)
unset( $sizes[ 'shop_catalog' ]); // Remove Shop catalog (300 x 300 hard cropped)
unset( $sizes[ 'shop_single' ]); // Shop single (600 x 600 hard cropped)
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'remove_default_image_sizes' );
Upvotes: 1