[Support request] add class to main product image on single product page

Home Forums Support add class to main product image on single product page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #964435
    Paul

    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

    #964604
    Tom
    Lead Developer
    Lead Developer

    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;
    } );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.