Site logo

[Resolved] With GP Premium all images have loading=”lazy”

Home Forums Support [Resolved] With GP Premium all images have loading=”lazy”

Home Forums Support With GP Premium all images have loading=”lazy”

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2552645
    Bernhard

    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.

    #2553045
    David
    Staff
    Customer Support

    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;
    }
    #2553140
    Bernhard

    Hi David,
    lazy is still there.

    #2553152
    David
    Staff
    Customer Support

    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');
    #2553259
    Bernhard

    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.

    #2553276
    David
    Staff
    Customer Support

    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

    #2553299
    Bernhard

    OK, now it’s gone 🙂 . Do I need both snippets or only the last one?

    #2553314
    David
    Staff
    Customer Support

    just the last one… and I need a large whiskey lol
    Glad to hear its working

    #2553356
    Bernhard

    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

    #2553706
    David
    Staff
    Customer Support

    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.

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