- This topic has 7 replies, 2 voices, and was last updated 2 years, 6 months ago by
Ying.
-
AuthorPosts
-
February 7, 2023 at 12:25 pm #2525020
Muhammad
Hi there,
Is there any way I can remove the loading=”lazy” attribute from the featured images on single post. I’ve excluded my featured images from lazy loading through WP Rocket and the setting didn’t appear to be working. When I contacted their support, they said that their plugin is working fine and it’s the most probably the theme that’s adding this attribute in the source code.
Anyways, I’ve found these two results through Googling https://generatepress.com/forums/topic/remove-loadinglazy-tag-for-featured-images/
https://generatepress.com/forums/topic/how-to-resize-featured-image-on-mobile/#post-1858309But I don’t know if the code mentioned in those posts will work for me. Or where should I put the code?
February 7, 2023 at 12:54 pm #2525050Ying
StaffCustomer SupportHi there,
Can I see one of your post with featured image?
February 7, 2023 at 1:45 pm #2525103Muhammad
I have added my post URL in private info field.
February 7, 2023 at 2:22 pm #2525136Ying
StaffCustomer SupportIt looks like you’ve already been using some custom functions to add the
first-featured-image
class to the featured image.Can you try adding the
first-featured-image
class to WP rocket’s exclusion list?February 7, 2023 at 2:36 pm #2525152Muhammad
I have already done that. And according to WP Rocket, this image is not being lazy loaded. But somehow the source code is still having the loading=”lazy” attribute that’s causing my core web vitals score to drop slightly.
This is what actually they said:
“…….As you can see in this screenshot, there are no lazyloaded class, data-ll-status=”loaded” , <noscript> tag, which means that the image is not lazy loaded by WP Rocket.
But yes, the attribute loading=”lazy” is present, and this is triggering the PageSpeed to warn you that the image is lazy loaded. However, attribute loading=”lazy” is not added by WP Rocket.
This is very likely added by the theme”February 7, 2023 at 3:44 pm #2525205Ying
StaffCustomer SupportI see,then it’s likely being lazyloaded by WP.
Try adding this PHP code to remove the lazyload attribute from the image with
first-featured-image
class :add_filter( 'wp_get_attachment_image_attributes', 'remove_lazy_load_attribute', 10, 3 ); function remove_lazy_load_attribute( $attributes, $attachment, $size ) { if ( isset( $attributes['class'] ) && strpos( $attributes['class'], 'first-featured-image' ) !== false ) { unset( $attributes['loading'] ); } return $attributes; }
February 8, 2023 at 10:50 am #2526278Muhammad
I added the code and now this attribute is removed. Thanks for the help
February 8, 2023 at 5:24 pm #2526565Ying
StaffCustomer SupportYou are welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.