How to Avoid Lazy Loading for a Single Image on WordPress Without a Plugin.

Last updated on January 6th, 2023.

I’ve spent a good while of my Sunday afternoon finding out how to lazy load just one entire image on WordPress. As you might know, since the WordPress 5.5 updates, WordPress loads all images with the lazy tag per default.

But when an image is above the fold, I advise disabling lazy loading as it can delay the largest contentful paint. And for SEO reasons we don’t want any delay there.

Without any further delay, here’s the fix:
1. Copy the code below:

/* Disable lazy loading for single image* */
function wphelp_no_lazy_load_id( $value, $image, $context ) {
if ( 'the_content' === $context ) {
$image_url = wp_get_attachment_image_url( 36, 'large' ); 
if ( false !== strpos( $image, ' src="' . $image_url . '"' )) {
return false;
return $value;
add_filter( 'wp_img_tag_add_loading_attr', 'wphelp_no_lazy_load_id', 36, 36 );

2. In the fourth and in the last line you see the value 36. This is the image id number of the image I want to change.
Replace the 36 with the image id of your image.
You find the image id in the code editor of the WordPress page/post. Here’s how to find it:

  • Click on the three dots in the upper right
  • Select the Code editor or use the shortcuts: ⇧⌥⌘M for Mac and Ctrl + Shift + Alt + M for Windows
  • find the image id in the code

3. On WordPress go to Appearance > Theme Editor > functions.php
4. Insert the code snippet there
5. Hit the “Update File” button

That’s it!

In the video below, I walk you live through every step.

If you feel like contributing to my coffee spend, you can do so here:
Thank you!

Corina Burri

Corina is a SEO Freelancer from Zürich. Since 2016 she's in SEO and has contributed to publications such as SEOFOMO, Tech SEO Tips, or iPullRank. When not grinding, she enjoys exploring Switzerland with her family.

This Post Has 11 Comments

  1. Thomas

    Thanks for the tip !

    Just have a question, what is the “add filter” part on the bottom with some IDs ?

  2. Corina

    Hi Thomas
    Thanks for pointing that out. tbh, the ids were a copy-paste error.

    The values in the last line should be the ids of the specific image you want to lazy load.
    I’ve updated the manual accordingly.
    Thanks for bringing my attention to it.

  3. Atif

    Hey there, I’ve used a code add_filter(‘wp_lazy_loading_enabled’,’__return_false’); in the function.php and that’s working for the homepage first image but it doesn’t lazy load the post featured image. How to lazy load post featured images? Please assist me in a better way. Your favor in this regard would be greatly appreciated. Thank you


  4. Jaci

    Thank you! This solved a loading bug in Safari!

  5. API Mike

    Hey, I’ve entered the script in my site (elementor + breeze) but it didn’t remove the tag, might there an issue with Elementor?

    1. Corina

      Hi Mike! Thank’s for asking. Unfortunately, I’m not familiar with Elementor. Fingers crossed, you’ll find the answer soon and feel free to share the solution!

  6. Andy

    I’m using Kadence and added the code with ‘code snippets’ to the php but it’s not working. Any ideas?

    1. Corina

      Hi Andy
      Unfortuneately, I don’t have the Kadence theme on none of my website. Therefore I’m not ableo to reproduce the lazy loading for one image with Kadence, I’m afraid.
      Anyone else is able to jump in and help Andy?


  7. Geert

    Hi Corina,
    thank you very much! It really helps.
    It helps so good, I would like to add this to all the images above the fold on the other pages of my site. Is that possible with this snippet? If so, how?
    Thanks again
    Kind regards

  8. TRM

    Hi Corina,

    just wondering: would it also be possible to avoid lazy load on the first image of a page? So not a certain ID, but the first embeded image?

  9. Kitty

    Hi, very nice. But it doesn’t help me if I have a block with background image, does it? There is no ID (which I could find in another way) and there is no Lazy Loading class on bg images.

Leave a Reply