Archived topic
Adding class to disable lazyload on featured image
5 replies · Started by Tan on August 24, 2020
Hi there,
I follow this guide to disable lazyload on featured image (on top every post).
I'm wanting to add the class “skip-lazy” to all featured images on my blog.
What could I do?
Thank for your help!
Thank you Leo.
After adding that snippet I can't see class through Chrome.
Could you visit my post and check it out? It's here.
I have a snippet to adding feature image through shortcode.
function db_feat_img_shortcode() {
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'hero', false );
return '<img src="' . $img_src[0] . '"/>';
}
add_shortcode( 'db_feat_img', 'db_feat_img_shortcode' );
And also have a hook to show them on blog.
Hi there,
in your function - you can change this line:
return '<img src="' . $img_src[0] . '"/>';
to this:
return '<img src="' . $img_src[0] . '" class="skip-lazy" />';
It worked.
Thank you so much David :)
You're welcome