[wp-trac] [WordPress Trac] #58211: Conditionally skip lazy-loading on images before the loop in classic themes
WordPress Trac
noreply at wordpress.org
Thu Apr 27 20:48:00 UTC 2023
#58211: Conditionally skip lazy-loading on images before the loop in classic themes
--------------------------+------------------------------------------
Reporter: flixos90 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.3
Component: Media | Version: 5.9
Severity: normal | Keywords: needs-patch needs-unit-tests
Focuses: performance |
--------------------------+------------------------------------------
[55318] includes an enhancement which for block themes avoids lazy-loading
images that appear in the `header` block template part. While that
resolves a common performance problem with lazy-loaded images in the
header of a page for block themes, sites using a classic theme still run
into this problem.
Specifically, in classic themes today only images that are rendered while
`in_the_loop()` are eligible to have lazy-loading skipped on them. This
ticket aims to introduce conditions to make images eligible for skipping
lazy-loading that are included ''before'' the loop.
We can fix the problem by updating `wp_get_loading_attr_default()` to omit
lazy-loading / return `false` if all of the following applies:
* `$context` is either "the_post_thumbnail" or "wp_get_attachment_image"
* the `get_header` action has already run
* the main query loop has not started yet
* the `get_footer` action has not yet run
This effectively results in images in the header but before the main query
loop to not be lazy-loaded. In cases where a special page template does
not contain a query loop, the `get_footer` action acts as a "fallback" to
ensure that footer images are still lazy-loaded.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58211>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list