• Hi,

    We have added the below code to our function.php file and yet when we view our source code we still see “lazy”.

    // Disable WordPress Lazy Load
    add_filter( 'wp_lazy_loading_enabled', '__return_false' );

    Please how do we disable this feature?

Viewing 10 replies - 1 through 10 (of 10 total)
  • You could try one of the two alternative codes. Look here: https://developer.www.ads-software.com/reference/functions/wp_lazy_loading_enabled/#comment-4226

    Also note that there are plugins and themes that bring LazyLoad itself. If this is the case, you would have to disable the function in the plugin or theme.

    Thread Starter Kingsley Felix

    (@iamkingsleyf)

    Thanks for the link but i don’t know what I need to get from there to fix the issue… the generally known one is not working

    There are two codes in the comment i linked above:

    To change how this feature works for specific attachments, the ‘loading’ attribute can be supplied to the wp_get_attachment_image function, or you can modify or remove the attribute using the wp_get_attachment_image_attributes filter.

    $attr['loading'] = false;
    return wp_get_attachment_image( $attachment_id, $size, $icon, $attr );

    Or:

    add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment, $size ) {
        if ( $attachment->post_mime_type === 'image/svg+xml' ) {
            unset( $attr['loading'] );
        }
        return $attr;
    } );
    • This reply was modified 2 years, 6 months ago by threadi.
    Thread Starter Kingsley Felix

    (@iamkingsleyf)

    No idea on the PHP or WordPress function
    sorry don’t be offended

    You could also hire someone to help you with this. Here you can find developers who can support you: https://jobs.wordpress.net

    add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment, $size ) {
        if ( $attachment->post_mime_type === 'image/svg+xml' ) {
            unset( $attr['loading'] );
        }
        return $attr;
    } );

    This gives error! Can you help?
    SCR: https://prnt.sc/yJ-7yQ_VCV_F

    • This reply was modified 2 years, 1 month ago by Pratyaksh. Reason: Added snapshot

    Change it to:

    add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment, $size ) {
        if ( $attachment->post_mime_type === 'image/svg+xml' ) {
            unset( $attr['loading'] );
        }
        return $attr;
    }, 10, 3 );

    And please open a separate topic next time. There you can then refer to this.

    Thread Starter Kingsley Felix

    (@iamkingsleyf)

    So the code is added to theme function.php file @threadi

    @threadi Thanks for the updated code. instructions well noted for future.
    Have a great day ahead.

    Thread Starter Kingsley Felix

    (@iamkingsleyf)

    @pratyaksh99 did you try it again?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘disable lazy load’ is closed to new replies.