Media: Allow for customization of lazy-loading featured images.
When lazy-loading images was introduced, in [52065] the check for `wp_lazy_loading_enabled()` was omitted by accident in the logic to set the attribute with its default value on `img` tags from `get_the_post_thumbnail()`. Without this check, it is impossible for third-party developers to modify the behavior for featured images. This changeset fixes the problem by introducing the check. Props flixos90, joemcgill, mukesh27. Fixes #57490. Built from https://develop.svn.wordpress.org/trunk@55093 git-svn-id: http://core.svn.wordpress.org/trunk@54626 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
18b551b84d
commit
1a21c14d85
|
@ -186,6 +186,8 @@ function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr =
|
||||||
update_post_thumbnail_cache();
|
update_post_thumbnail_cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add `loading` attribute.
|
||||||
|
if ( wp_lazy_loading_enabled( 'img', 'the_post_thumbnail' ) ) {
|
||||||
// Get the 'loading' attribute value to use as default, taking precedence over the default from
|
// Get the 'loading' attribute value to use as default, taking precedence over the default from
|
||||||
// `wp_get_attachment_image()`.
|
// `wp_get_attachment_image()`.
|
||||||
$loading = wp_get_loading_attr_default( 'the_post_thumbnail' );
|
$loading = wp_get_loading_attr_default( 'the_post_thumbnail' );
|
||||||
|
@ -198,6 +200,7 @@ function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr =
|
||||||
} elseif ( is_string( $attr ) && ! preg_match( '/(^|&)loading=/', $attr ) ) {
|
} elseif ( is_string( $attr ) && ! preg_match( '/(^|&)loading=/', $attr ) ) {
|
||||||
$attr .= '&loading=' . $loading;
|
$attr .= '&loading=' . $loading;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
|
$html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-alpha-55092';
|
$wp_version = '6.2-alpha-55093';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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