3

Wordpress adds lazy loading on all images. Lighthouse recommends disabling lazy loading on images in above the folder. I would like to figure out how to disable it only on images that I call with wp_get_attachment_image_src in my templates, so that I can control exactly which LCP images to remove lazy load.

Lighthouse documentation: https://web.dev/lcp-lazy-loading/?utm_source=lighthouse&utm_medium=lr

1 Answer 1

10

You can manage WordPress lazy loading with the loading parameter. Below code echo's your image without using the lazy load function.

echo wp_get_attachment_image( $image, $size, false, [
  'class' => 'your-class-here', 
  'loading' => 'eager'
] );
2
  • Great! It was just what I wanted. Thank you! Commented Dec 24, 2021 at 13:54
  • You are very welcome. Have a nice day! :)
    – DeltaG
    Commented Dec 24, 2021 at 13:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.