mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-10 22:06:55 +01:00
Media: Ensure that large images before the main query loop are counted towards lazy-loading threshold.
Following [55318], [55847], and [56142], certain images in the header of the page have received support for potentially receiving `fetchpriority="high"` and having the `loading="lazy"` attribute omitted. However, these images being present did not affect the "content media count" which counts the images towards a certain threshold so that the first ones are not lazy-loaded. This changeset also increases that count for such header images if they are larger than a certain threshold. The threshold is used to avoid e.g. a header with lots of small images such as icon graphics to skew the lazy-loading behavior. Props thekt12, spacedmonkey, flixos90. Fixes #58635. Built from https://develop.svn.wordpress.org/trunk@56143 git-svn-id: http://core.svn.wordpress.org/trunk@55655 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9ecfdd8e5a
commit
fb9013c9b4
@ -5588,6 +5588,15 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
|
|||||||
}
|
}
|
||||||
return $loading_attributes;
|
return $loading_attributes;
|
||||||
};
|
};
|
||||||
|
// Closure to increase media count for images with certain minimum threshold, mostly used for header images.
|
||||||
|
$maybe_increase_content_media_count = static function() use ( $attr ) {
|
||||||
|
/** This filter is documented in wp-admin/includes/media.php */
|
||||||
|
$wp_min_priority_img_pixels = apply_filters( 'wp_min_priority_img_pixels', 50000 );
|
||||||
|
// Images with a certain minimum size in the header of the page are also counted towards the threshold.
|
||||||
|
if ( $wp_min_priority_img_pixels <= $attr['width'] * $attr['height'] ) {
|
||||||
|
wp_increase_content_media_count();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$loading_attrs = array();
|
$loading_attrs = array();
|
||||||
|
|
||||||
@ -5640,11 +5649,15 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
|
|||||||
*/
|
*/
|
||||||
$header_area = WP_TEMPLATE_PART_AREA_HEADER;
|
$header_area = WP_TEMPLATE_PART_AREA_HEADER;
|
||||||
if ( "template_part_{$header_area}" === $context ) {
|
if ( "template_part_{$header_area}" === $context ) {
|
||||||
|
// Increase media count if there are images in header above a certian minimum size threshold.
|
||||||
|
$maybe_increase_content_media_count();
|
||||||
return $postprocess( $loading_attrs, true );
|
return $postprocess( $loading_attrs, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
// The custom header image is always expected to be in the header.
|
// The custom header image is always expected to be in the header.
|
||||||
if ( 'get_header_image_tag' === $context ) {
|
if ( 'get_header_image_tag' === $context ) {
|
||||||
|
// Increase media count if there are images in header above a certian minimum size threshold.
|
||||||
|
$maybe_increase_content_media_count();
|
||||||
return $postprocess( $loading_attrs, true );
|
return $postprocess( $loading_attrs, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5671,6 +5684,8 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
|
|||||||
*/
|
*/
|
||||||
&& did_action( 'get_header' ) && ! did_action( 'get_footer' )
|
&& did_action( 'get_header' ) && ! did_action( 'get_footer' )
|
||||||
) {
|
) {
|
||||||
|
// Increase media count if there are images in header above a certian minimum size threshold.
|
||||||
|
$maybe_increase_content_media_count();
|
||||||
return $postprocess( $loading_attrs, true );
|
return $postprocess( $loading_attrs, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.3-beta3-56142';
|
$wp_version = '6.3-beta3-56143';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user