Archived topic
With GP Premium all images have loading="lazy"
9 replies · Started by Bernhard on March 2, 2023
Hi there,
it seems that GP Premium adds to all images loading="lazy"
My featured images in the header block have the class crazy-load added to trigger disabling of lazy load.
`
When I used WP Rocket or Litespeed, these plugins filter loading="lazy" out. But I had to disable both due to compatibility issues with Ezoic and the Ezoic optimization "Leap" loops thru the lazy load and does not filter it out.
My test setup:
With litespeed plugin appears no "lazy"
Disabling litespeed "lazy" appears
Then I disabled all plugins until "lazy" disappeared and this is only when GP Premium is disabled. Other plugins still active in my setup are GP Blocks, GP Blocks pro and Polylang.
Screenshots:
GP Premium active
GP Premium disabled
I need to solve the problem urgently.
Hi there,
try adding the following PHP Snippets to your site:
add_filter( 'wp_omit_loading_attr_threshold', function($omit_threshold){
if ( is_single() ) {
$omit_threshold = 0;
}
return $omit_threshold;
} );
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'], 'attachment-full' ) ) {
unset( $attr['loading'] );
}
return $attr;
}
Hi David,
lazy is still there.
Sorry i think i sent you the wrong PHP
Try:
function disable_lazy_load_featured_images($attr, $attachment = null) {
unset( $attr['loading'] );
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'disable_lazy_load_featured_images');
Hi David,
now it says image loading="lazy"
Screenshot
I would prefer to disable the lazy loading completely in GP Premium and to address it in an optimization system using the CSS classes.
damn... I am having a day of it lol
The loading=lazy attribute comes from WP.
Theme simply uses certain core functions like getting the image, that adds them.
Add this snippet:
add_filter( 'wp_lazy_loading_enabled', '__return_false' );
This will tell WP to stop it
OK, now it's gone :) . Do I need both snippets or only the last one?
just the last one... and I need a large whiskey lol
Glad to hear its working
Not only you :)
I have been looking into this for over half a year, but I had never done this test. Simply because I couldn't imagine GP Premium interfering with lazy-load on images.
In any case, I'm glad it's solved now.
Thank you David and cheers, have a nice day
Just to be clear, its WordPress that adds the loading=lazy attribute.
The only thing GP Premium does ( alllows ) is the (re)moving of the featured image, which can result in certain WP functions behaving differently. Theres more info on that here if you want boring read lol
Glad to hear its working.