mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-05 07:58:35 +01:00
Media: Enhance logic to determine LCP image in block themes and avoid lazy-loading it.
[52065] originally introduced the logic to guess the LCP image based on certain heuristics and to not lazy-load that image. However, with the introduction of block themes, that logic was not functioning correctly, resulting in all featured images to be lazy-loaded, regardless of whether it was the LCP image or not. Together with an update to the `core/post-featured-image` block included in [55079], this changeset fixes the logic to correctly handle featured images in block themes as well. Additionally, in combination with an update to the `core/template-part` block from [55246], this changeset includes an enhancement which uses the benefits of block template parts to avoid lazy-loading images in the `header` block template part, making the lazy-loading heuristics even more accurate for sites using a block theme. Props flixos90, adamsilverstein, mamaduka, antonvlasenko, shahidul95, reduanmasud, costdev, mukesh27, ironprogrammer, manfcarlo, robinwpdeveloper, spacedmonkey. Fixes #56930. Built from https://develop.svn.wordpress.org/trunk@55318 git-svn-id: http://core.svn.wordpress.org/trunk@54851 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
588b002955
commit
1da2841c07
@ -241,7 +241,7 @@ function get_the_block_template_html() {
|
|||||||
$content = wptexturize( $content );
|
$content = wptexturize( $content );
|
||||||
$content = convert_smilies( $content );
|
$content = convert_smilies( $content );
|
||||||
$content = shortcode_unautop( $content );
|
$content = shortcode_unautop( $content );
|
||||||
$content = wp_filter_content_tags( $content );
|
$content = wp_filter_content_tags( $content, 'template' );
|
||||||
$content = do_shortcode( $content );
|
$content = do_shortcode( $content );
|
||||||
$content = str_replace( ']]>', ']]>', $content );
|
$content = str_replace( ']]>', ']]>', $content );
|
||||||
|
|
||||||
|
@ -5444,11 +5444,22 @@ function wp_get_webp_info( $filename ) {
|
|||||||
* that the `loading` attribute should be skipped.
|
* that the `loading` attribute should be skipped.
|
||||||
*/
|
*/
|
||||||
function wp_get_loading_attr_default( $context ) {
|
function wp_get_loading_attr_default( $context ) {
|
||||||
// Only elements with 'the_content' or 'the_post_thumbnail' context have special handling.
|
// Skip lazy-loading for the overall block template, as it is handled more granularly.
|
||||||
if ( 'the_content' !== $context && 'the_post_thumbnail' !== $context ) {
|
if ( 'template' === $context ) {
|
||||||
return 'lazy';
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not lazy-load images in the header block template part, as they are likely above the fold.
|
||||||
|
$header_area = WP_TEMPLATE_PART_AREA_HEADER;
|
||||||
|
if ( "template_part_{$header_area}" === $context ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded,
|
||||||
|
* as they are likely above the fold.
|
||||||
|
*/
|
||||||
|
if ( 'the_content' === $context || 'the_post_thumbnail' === $context ) {
|
||||||
// Only elements within the main query loop have special handling.
|
// Only elements within the main query loop have special handling.
|
||||||
if ( is_admin() || ! in_the_loop() || ! is_main_query() ) {
|
if ( is_admin() || ! in_the_loop() || ! is_main_query() ) {
|
||||||
return 'lazy';
|
return 'lazy';
|
||||||
@ -5464,6 +5475,10 @@ function wp_get_loading_attr_default( $context ) {
|
|||||||
|
|
||||||
// For elements after the threshold, lazy-load them as usual.
|
// For elements after the threshold, lazy-load them as usual.
|
||||||
return 'lazy';
|
return 'lazy';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lazy-load by default for any unknown context.
|
||||||
|
return 'lazy';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-beta1-55317';
|
$wp_version = '6.2-beta1-55318';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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