#58212 closed enhancement (fixed)
Improve clunky logic to inject `loading` attribute in the `get_the_post_thumbnail()` function
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.3 | Priority: | high |
Severity: | normal | Version: | |
Component: | Post Thumbnails | Keywords: | has-patch, has-unit-tests, add-to-field-guide, has-dev-note |
Focuses: | performance | Cc: |
Description
The get_the_post_thumbnail()
function contains a somewhat hacky workaround today to compute the loading
attribute (via wp_get_loading_attr_default()
. While it uses wp_get_attachment_image()
for basically all its markup, the loading
attribute is already calculated before, which works technically okay, but has several drawbacks - most importantly there is no context on other attributes available in that function, and there is a risk of potentially calling the function again for the same image which would skew the content media count.
This logic should be changed so that the wp_get_loading_attr_default()
function call from wp_get_attachment_image()
is used, even when the latter is invoked by get_the_post_thumbnail()
. We can apply use of the being_fetch_post_thumbnail_html
and being_fetch_post_thumbnail_html
actions to conditionally change the $context
value passed to wp_get_loading_attr_default()
, in a similar way to how they are already used today to add the wp-post-image
CSS class to such image tags.
Change History (11)
This ticket was mentioned in PR #4390 on WordPress/wordpress-develop by @flixos90.
22 months ago
#1
- Keywords has-patch added; needs-patch removed
#2
@
22 months ago
- Priority changed from normal to high
Addressing the remaining lazy-loading related performance issues is a high priority for the performance team for the 6.3 cycle.
@flixos90 commented on PR #4390:
21 months ago
#3
@kt-12 FYI since you're working on some of the other lazy-load related tickets.
#4
@
21 months ago
- Keywords has-unit-tests added; needs-unit-tests removed
PR https://github.com/WordPress/wordpress-develop/pull/4390 is now ready for a full review.
@flixos90 commented on PR #4390:
21 months ago
#5
@kt-12 @spacedmonkey @westonruter I've replied to your feedback and made some updates.
@flixos90 commented on PR #4390:
21 months ago
#7
Committed via https://core.trac.wordpress.org/changeset/55821
Trac ticket: https://core.trac.wordpress.org/ticket/58212