• Resolved scrlk

    (@scrlk)


    I have enabled lazy loading but it doesn’t lazy load my images (according to google speed tests). I’ve coded my page using PHP and display images with an tag. Is there something I need in the tag to enable lazy loading? I know that WP 5.5 needs a width and height to enable lazy loading. Is there something in SG that is needed?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Stanimir Stoyanov

    (@sstoqnov)

    SiteGround Representative

    Hey @scrlk

    Our Lazy Load Optimization doesn’t work with manually added images.

    If you want to use this feature, you should use the default WordPress image display functions like:

    
    wp_get_attachment_image_url
    get_post_thumbnail_url
    etc
    

    Because we use the hooks in the functions mentioned above to lazyload the images.
    And without these hooks, this optimization cannot work.

    Regards,
    Stanimir

    Thread Starter scrlk

    (@scrlk)

    Okay, at least I’m using the correct function. I am using wp_get_attachment_image_url() to pull the image. But it’s still not working…

    Here is how my code is setup. I prepare all the data ahead of time in a loop because I output the same image in a couple of places.

    loop1
    (do some stuff)
    $data[$count]['image'] = get_post_thumbnail_url()
    (do some more stuff)
    endloop1
    
    loop2
    (do some stuff)
    echo '<img src="'.$data[$count]['image'].'" alt="'.$data[$count]['name'].'"></a>';
    (do some more stuff)
    endloop2
    
    loop3
    (do some stuff)
    echo '<img src="'.$data[$count]['image'].'" alt="'.$data[$count]['name'].'"></a>';
    (do some more stuff)
    endloop3
    

    Is this why the lazy loading doesn’t work? What would be the proper approach in PHP to get it working?

    • This reply was modified 4 years ago by scrlk.
    • This reply was modified 4 years ago by scrlk.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Lazy Load Not Working’ is closed to new replies.