Media: Prevent special images within post content to skew image counts and cause lazy-loading bugs.
In order to skip lazy-loading the first few images on a page, as of WordPress 5.9 there has been logic to count images that are eligible based on certain criteria. One of those groups are images that appear within the content of a post. This changeset fixes a bug where images created via `get_the_post_thumbnail()` or `wp_get_attachment_image()` that are injected into the post content would skew the count and therefore result in all images to be lazy-loaded, potentially hurting load time performance. This is relevant for example when those functions are called in server-side rendered blocks, or any other filter callbacks hooked into `the_content`. Props flixos90, antpb, joedolson, spacedmonkey, mukesh27, thekt12, costdev, jrf. Fixes #58089. See #53675. Built from https://develop.svn.wordpress.org/trunk@55825 git-svn-id: http://core.svn.wordpress.org/trunk@55337 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
be4b739a49
commit
2b28fea7c9
|
@ -5506,6 +5506,16 @@ function wp_get_loading_attr_default( $context ) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip programmatically created images within post content as they need to be handled together with the other
|
||||
* images within the post content.
|
||||
* Without this clause, they would already be counted below which skews the number and can result in the first
|
||||
* post content image being lazy-loaded only because there are images elsewhere in the post content.
|
||||
*/
|
||||
if ( ( 'the_post_thumbnail' === $context || 'wp_get_attachment_image' === $context ) && doing_filter( 'the_content' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded,
|
||||
* as they are likely above the fold.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.3-alpha-55824';
|
||||
$wp_version = '6.3-alpha-55825';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue