[wp-trac] [WordPress Trac] #56927: Post Featured Image always lazy loaded in T22 and T23 Single template

WordPress Trac noreply at wordpress.org
Fri Oct 28 14:57:31 UTC 2022


#56927: Post Featured Image always lazy loaded in T22 and T23 Single template
-----------------------------+-----------------------------
 Reporter:  RavanH           |      Owner:  (none)
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Post Thumbnails  |    Version:  6.1
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 To my surprise, in Twenty Twenty-Two and Twenty-Three the featured post
 images are always lazy loaded. This, in spite of the fact that the
 featured image is the frist image on the screen, so ignoring the
 `wp_omit_loading_attr_threshold` of 1.

 I tried returning false on the `wp_lazy_loading_enabled` filter but that
 did not have any effect either.

 It appears that the Post Featured Image block, using
 get_the_post_thumbnail ignores both `wp_lazy_loading_enabled` filter and
 `wp_omit_loading_attr_threshold`.

 The lines in question, starting at line 191 in wp-includes/post-thumbnail-
 template.php:

 {{{
                 // Get the 'loading' attribute value to use as default,
 taking precedence over the default from
                 // `wp_get_attachment_image()`.
                 $loading = wp_get_loading_attr_default(
 'the_post_thumbnail' );

                 // Add the default to the given attributes unless they
 already include a 'loading' directive.
                 if ( empty( $attr ) ) {
                         $attr = array( 'loading' => $loading );
                 } elseif ( is_array( $attr ) && ! array_key_exists(
 'loading', $attr ) ) {
                         $attr['loading'] = $loading;
                 } elseif ( is_string( $attr ) && ! preg_match(
 '/(^|&)loading=/', $attr ) ) {
                         $attr .= '&loading=' . $loading;
                 }

                 $html = wp_get_attachment_image( $post_thumbnail_id,
 $size, false, $attr );

 }}}

 Here, `wp_get_loading_attr_default( 'the_post_thumbnail' )` apparently
 returns 'lazy' even if it is the first image on the page, which causes the
 loading attribute to be set and passed to `wp_get_attachment_image` which
 then ignores the usual `wp_lazy_loading_enabled` validation.

 Why does `wp_get_loading_attr_default( 'the_post_thumbnail' )` return true
 in this case? Does `in_the_loop()` return false at this point?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56927>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list