Archived topic
Excluding featured image for Shortpixel Adaptive Images
13 replies · Started by David on July 1, 2020
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?
Hi there,
What if you try img.wp-post-image?
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)
Hi there,
Is this on a single post/page with the main featured image at the top?
That's correct! All single posts and pages with a featured image.
Can you share a link to a post or page - it will help me look for a solution.
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.
Genius solution! This worked. Thank you.
You're welcome
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/
Try replacing is_single() for is_singular()
Thank you! (Updated all "single" mentions in that code snippet to "singular" and worked)
You're welcome