• Hi

    WC add a few image size,
    – woocommerce_thumbnail
    – woocommerce_single
    – woocommerce_galleru_thumbnail.

    Now if I upload a normal post or an image through another plugin/cpt, then these sizes are also created.

    I really would like to limit the creation of images size to the relevant post type with something like this:

        if( get_post_type() !== 'product' ) {
          remove_image_size( 'woocommerce_thumbnail' );
          remove_image_size( 'woocommerce_single' );
          remove_image_size( 'woocommerce_gallery_thumbnail' );
          remove_image_size( 'shop_catalog' );
          remove_image_size( 'shop_single' );
          remove_image_size( 'shop_thumbnail' );
        }
Viewing 1 replies (of 1 total)
  • Thread Starter Schalk Joubert

    (@schalkjoubert)

    This seems to be working when I added an image to another CPT
    But when I added a product image, none of the WC image sizes was created…

    function remove_wc_image_sizes() {
     if( get_post_type() !== 'product' ) {
          remove_image_size( 'woocommerce_thumbnail' );
          remove_image_size( 'woocommerce_single' );
          remove_image_size( 'woocommerce_gallery_thumbnail' );
          remove_image_size( 'shop_catalog' );
          remove_image_size( 'shop_single' );
          remove_image_size( 'shop_thumbnail' );
        }
    }
    add_action('init', 'remove_wc_image_sizes');
Viewing 1 replies (of 1 total)
  • The topic ‘Restrict add_image_size to Woocommerce Post type only’ is closed to new replies.