[wp-trac] [WordPress Trac] #53675: Omit lazy-loading attribute on first content image/iframe
WordPress Trac
noreply at wordpress.org
Tue Jul 20 01:03:10 UTC 2021
#53675: Omit lazy-loading attribute on first content image/iframe
------------------------------------------+--------------------------
Reporter: flixos90 | Owner: flixos90
Type: enhancement | Status: assigned
Priority: normal | Milestone: 5.9
Component: Media | Version: 5.5
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses: performance
------------------------------------------+--------------------------
Comment (by westonruter):
Replying to [comment:3 flixos90]:
> @westonruter This is close to what I did in the prototype plugin used
for the analysis - the one thing missing from yours (as you mention in the
other ticket) was archive support. It would be great if you could review
the prototype plugin (see below) and leave your thoughts.
Actually, my plugin does account for the archive template. My comment was
referring to how twentytwentyone was not omitting `loading=lazy` from the
first post's featured image on an archive template.
In your POC, you're stripping out `loading="lazy"` from the HTML of the
featured image. Would it not be better to rather filter
`wp_lazy_loading_enabled`? See
[https://gist.github.com/westonruter/e8d5778843005b7e0d6ce4049b3ec29d
#file-prevent-lazy-loading-primary-featured-image-php-L75 alternative].
It's good how you're using `wp_img_tag_add_loading_attr` to account for
markup in the content beyond just the featured image.
What if someone is adding an image to the template outside of
`the_content()` and `the_post_thumbnail()`? They could also obtain an
image via `wp_get_attachment_image()` directly. Since that function
applies the `wp_lazy_loading_enabled` filter, perhaps the filter should
increment the counter instead of in the `post_thumbnail_html` and
`wp_img_tag_add_loading_attr` filters both?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53675#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list