Twenty Twenty-One: Do not specify loading=“eager” for single post thumbnails.

While `loading=“eager”` is a supported alternative to omitting the attribute entirely, browsers follow the value of this attribute explicitly when specified.

Specifying `eager` would prevent the user from receiving any additional potential benefits implemented at the browser level, such as further mechanisms to automatically decide which elements to lazy-load.

Props flixos90, ryelle, poena.
Merges [49860] to the 5.6 branch.
Fixes #52139.

git-svn-id: https://develop.svn.wordpress.org/branches/5.6@49861 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2020-12-21 18:49:22 +00:00
parent 29de440b0b
commit 2fa61935fe

View File

@ -190,8 +190,8 @@ if ( ! function_exists( 'twenty_twenty_one_post_thumbnail' ) ) {
<figure class="post-thumbnail">
<?php
// Thumbnail is loaded eagerly because it's going to be in the viewport immediately.
the_post_thumbnail( 'post-thumbnail', array( 'loading' => 'eager' ) );
// Lazy-loading attributes should be skipped for thumbnails since they are immediately in the viewport.
the_post_thumbnail( 'post-thumbnail', array( 'loading' => false ) );
?>
<?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
<figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?></figcaption>