1

since WP 5.5, I had to add this function to my theme to prevent rendering issues in an image slider due to automatic lazy loading in WP:

    add_filter( 'wp_lazy_loading_enabled', '__return_false' );

This was working quite well since it was removing the automatic parameter "loading=lazy" on images elements.

Yesterday, after upgrading to WP 5.9, I'm facing the same issue again with my slider and I see that the "loading=lazy" parameter is back on all images!

How can I fix that? Thanks

3
  • Please see the change log for this function to see if there's any changes needed in the hook: github.com/WordPress/wordpress-develop/blob/5.9/src/wp-includes/… Commented Feb 10, 2022 at 15:03
  • Are you using a plugin for your slider? I haven't seen an issue with this filter (using it for the same reason you are) after upgrading to 5.9. Commented Feb 10, 2022 at 15:27
  • No, no plugin here! Commented Apr 19, 2022 at 7:40

1 Answer 1

1

You can try one of these two solutions:

$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;
} );

Answer is from here: https://developer.wordpress.org/reference/functions/wp_lazy_loading_enabled/#comment-4226

Sign up to request clarification or add additional context in comments.

1 Comment

All filters solutions didn't worked but forcing 'loading' attribute while printing the image solved my problem! Thanks Cray

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.