Site logo

Archived topic

add class to main product image on single product page

1 reply · Started by Paul on July 22, 2019

Viewing posts 1–2 of 2

Good afternoon,

I'm looking for a piece of code I can plug into my functions.php that would add a custom class name to the main product image on woocommerces single product pages.

Example page: https://www.hearmeraw.uk/buy/saco2-filtered-mushroom-bags/

background: I'm using a lazy load script to lazy load the images, but I'd like the main product image to be excluded, and I can do this if I add a custom class to the <img property of the main image. ie: 'no-lazy'

Any help would be greatly appreciated.

Thanks,
Paul

Hi there,

I'm not sure if this will do it or not, but give it a shot:

add_filter( 'woocommerce_single_product_image_gallery_classes', function( $classes ) {
    $classes[] = 'your-class';

    return $classes;
} );
This archived topic is closed to new replies.