- This topic has 13 replies, 4 voices, and was last updated 6 months, 1 week ago by
David.
-
AuthorPosts
-
July 1, 2020 at 9:05 am #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?
July 1, 2020 at 9:27 am #1348522Leo
StaffCustomer SupportHi there,
What if you try
img.wp-post-image
?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/July 1, 2020 at 1:27 pm #1348767David
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)
July 1, 2020 at 2:43 pm #1348814Tom
Lead DeveloperLead DeveloperHi there,
Is this on a single post/page with the main featured image at the top?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJuly 1, 2020 at 3:39 pm #1348834David
That’s correct! All single posts and pages with a featured image.
July 2, 2020 at 2:59 am #1349169David
StaffCustomer SupportCan you share a link to a post or page – it will help me look for a solution.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/July 2, 2020 at 7:18 am #1349420July 2, 2020 at 8:02 am #1349606David
StaffCustomer SupportTry 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.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/July 2, 2020 at 9:12 am #1349677David
Genius solution! This worked. Thank you.
July 2, 2020 at 9:15 am #1349682David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/July 13, 2020 at 2:04 pm #1362444David
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/
July 14, 2020 at 1:07 am #1362785David
StaffCustomer SupportTry replacing
is_single()
foris_singular()
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/July 14, 2020 at 6:23 am #1363050David
Thank you! (Updated all “single” mentions in that code snippet to “singular” and worked)
July 14, 2020 at 7:43 am #1363128David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.