- This topic has 7 replies, 3 voices, and was last updated 2 years, 7 months ago by
Fernando.
-
AuthorPosts
-
November 29, 2022 at 2:41 am #2440615
Roberto
Hi,
I’m trying to not lazy load the first image in my website (https://giacomodenanni.it) adding “skip-lazy” class and data-skip-lazy attribute, but it seems to not having effects. I’m using WordPress default lazy load.
Do you have any suggestion?
Thanks!
November 29, 2022 at 4:18 am #2440743David
StaffCustomer SupportHi there,
add this PHP Snippet to your site.
Then any Image block with theskip-lazy
class should be excluded.add_filter( 'wp_get_attachment_image_attributes', 'fp_no_lazy_featured_image', 10, 3 ); function fp_no_lazy_featured_image( $attr ) { if ( false !== strpos( $attr['class'], 'skip-lazy' ) ) { $attr['loading'] = "eager"; } return $attr; }
As a general note – above the fold images “should” be automatically excluded from the native browser lazy loading.
November 29, 2022 at 8:56 am #2441411Roberto
Hi,
I add the code tofunctions.php
file, and classskip-lazy
to the Image Block, but Google Lighthouse or GTMetrix still showing the issue “Don’t lazy load Largest Contentful Paint image”, testing the homepage .
I don’t know if you need this information, but I’m using Autoptimize, using your suggested settings, so without lazy load setting, only the WordPress one.Do you have any suggestion to lower the LCP measure and fix the issue above?
ThanksNovember 29, 2022 at 9:25 am #2441477David
StaffCustomer SupportI made a change to the PHP snippet above, can you try that:
https://generatepress.com/forums/topic/how-disable-lazy-load-for-a-specific-image/#post-2440743
November 30, 2022 at 2:37 pm #2443591Roberto
Hi, thank you so much David. Unfortunately the snippet is still not functioning.
Do you have any other suggestion? Isn’t really strange that it’s not functioning?Thanks again!
November 30, 2022 at 7:00 pm #2443804Fernando Customer Support
Hi Giacomo,
The
loading="lazy"
attribute is a browser-level lazy loader. By default images above the fold will not be lazy-loaded by it.With that said, GTMetrix may be a little out of date on that. The native browser lazy loading on Chromium browsers ignores images above the fold – See here for more info: https://web.dev/browser-level-image-lazy-loading/#distance-from-viewport-thresholds
But if you want to remove the attribute then see the snippet one user provided here:
Moreover, do you have any other plugins for image lazy loading? I see you have Autoptimize which has such a feature. Can you temporarily disable it along with any other plugin with such a feature, and then test here: https://pagespeed.web.dev/
January 4, 2023 at 4:51 pm #2484036Roberto
Unfortunately I couldn’t fix the issue, so I decided to set image lazy loading with Autoptimize with exception for the first two images above the fold.
So far so good.January 4, 2023 at 5:21 pm #2484050Fernando Customer Support
I see. Glad you resolved the issue!
-
AuthorPosts
- You must be logged in to reply to this topic.