[Resolved] Excluding featured image for Shortpixel Adaptive Images

Home Forums Support [Resolved] Excluding featured image for Shortpixel Adaptive Images

Home Forums Support Excluding featured image for Shortpixel Adaptive Images

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1348476
    David

    Hello,

    We want to exclude the featured image from Shortpixel AI’s lazy load.

    However, the featured image has the same class as all images in WP Show Posts which we use below all our articles (.attachment-full)

    Therefore, we aren’t able to exclude the featured from lazy loading without also excluding all the images in WP Show posts.

    I’ve tried adding the parent class to shortpixel, but that only seems to work when the image is inline. (The code I tried was “.featured image img.attachment.full” and “.page-header-image-single img.attachment-full” without quotes, neither worked)

    Do you have any recommendations on how I can single out the featured image without also catching WP Show Posts images?

    #1348522
    Leo
    Staff
    Customer Support

    Hi there,

    What if you try img.wp-post-image?

    #1348767
    David

    Hi, my challenge is to single out the article’s featured image rather than the wp post images.

    It’s the featured image I try to exclude, so that’s the id I need to add to Shortpixels exclude list (without invoking the wp post images)

    #1348814
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Is this on a single post/page with the main featured image at the top?

    #1348834
    David

    That’s correct! All single posts and pages with a featured image.

    #1349169
    David
    Staff
    Customer Support

    Can you share a link to a post or page – it will help me look for a solution.

    #1349420
    David
    #1349606
    David
    Staff
    Customer Support

    Try adding this PHP Snippet:

    function db_add_class_to_single_featured_image($attr) {
        remove_filter('wp_get_attachment_image_attributes','db_add_class_to_single_featured_image');
        if ( is_single() ) {
            $attr['class'] .= ' no-lazy';
        }
        return $attr;
    }
    add_filter('wp_get_attachment_image_attributes','db_add_class_to_single_featured_image'); 

    it will add the no-lazy class, which you can change to whatever, to the single post featured image.

    #1349677
    David

    Genius solution! This worked. Thank you.

    #1349682
    David
    Staff
    Customer Support

    You’re welcome

    #1362444
    David

    Is it possible to modify this code so that it also adds a no-lazy to featured images on pages? (Not just posts)

    Example page: https://socialpronow.com/start-conversation/

    #1362785
    David
    Staff
    Customer Support

    Try replacing is_single() for is_singular()

    #1363050
    David

    Thank you! (Updated all “single” mentions in that code snippet to “singular” and worked)

    #1363128
    David
    Staff
    Customer Support

    You’re welcome

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.