Home › Forums › Support › Featured image show lazy and first image of post not lazy in generepress premium
- This topic has 24 replies, 5 voices, and was last updated 3 years, 5 months ago by
David.
-
AuthorPosts
-
October 26, 2022 at 11:06 am #2388470
Diogenes
Hi.
Yesterday version 2.2.0 of GP premium was released that supposedly fixed this error, but unfortunately it remained.
My setting for the featured image on blog posts is: above the content area.
I mention it, because when you place the featured image (for example) above the title, it works correctly (that is, featured image is not lazy, first image of the post: lazy. But placed: above the content area, the error remains .
I appreciate the comments.
October 26, 2022 at 7:33 pm #2388954Tom
Lead DeveloperLead DeveloperHmm, strange. It’s the same function that serves the image regardless of where you place it. Not sure why placing it outside of the content area would make a difference.
Do you have any custom functions added to the site regarding featured images?
October 27, 2022 at 7:44 am #2389787Diogenes
Hi Tom, thanks for replying.
Just like last time, on my test website where I don’t have any custom code, the same error occurs.
It seems that the bug is with respect to the featured image of the blog when it is placed in: above the content area
I leave you the credentials as administrator of my test site in the private information area, in case you want to see it for yourself.
October 27, 2022 at 8:33 am #2390117David
StaffCustomer SupportOk, so i been doing a little more digging and testing.
There are many cases as to when WP adds theloading=lazyattribute.
The two instances here are:1. when using
wp_get_attachment_imagewhich GP uses for displaying the featured image.2. all images within the loop that are past the
wp_omit_loading_attr_thresholdvalue which defaults to1.So when the featured image is within the loop ( eg. after title ) it gets counted in ( point 2 ) the
wp_omit_loading_attr_threshold– so the loading=lazy attribute that would be added because of thewp_get_attachment_imagewould get removed.However when the featured image is above the content, it sits outside of the loop.
So it gets the attribute from point #1 but doesn’t count for point #2.To prove this logic, add this PHP Snippet:
add_filter( 'wp_omit_loading_attr_threshold', function($omit_threshold){ if ( is_single() ) { $omit_threshold = 0; } return $omit_threshold; } );It will set omit threshold to
0so all images with the post content should have theloading=lazyattribute.If that works we just need to look at omitting the attribute from the featured image.
October 27, 2022 at 10:28 am #2390246Diogenes
Hi David.
Yes, with that code, the first image of the post is lazy loaded, so that would solve half of the problem.
It would be necessary to remove the lazy load of the featured image, as you comment.
October 30, 2022 at 5:11 am #2393755Diogenes
Any help here?.
November 1, 2022 at 10:16 am #2397082Diogenes
Any help here?
November 2, 2022 at 2:43 am #2397874David
StaffCustomer SupportHi there,
apologies, i thought i had replied.
Try this snippet:add_filter( 'wp_get_attachment_image_attributes', 'fp_no_lazy_featured_image', 10, 3 ); function fp_no_lazy_featured_image( $attr ) { if ( false !== strpos( $attr['class'], 'attachment-full' ) ) { unset( $attr['loading'] ); } return $attr; }November 4, 2022 at 7:10 am #2401478Diogenes
It works perfect, thanks David.
November 4, 2022 at 7:59 am #2401713David
StaffCustomer SupportYou’re welcome
We’ll look to see if we can disable that on the Above Content Featured image by default 🙂 -
AuthorPosts
- You must be logged in to reply to this topic.