Make WordPress Core

#56927 closed defect (bug) (duplicate)

Post Featured Image always lazy loaded in T22 and T23 Single template

Reported by: ravanh's profile RavanH Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Editor Keywords:
Focuses: Cc:


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?

Change History (4)

#1 @RavanH
19 months ago

I do not see a way to prevent this from happening to a Post Featured Image block used in a theme template, outside of the Loop like in the Single and Page templates in T22 and T23.

Maybe the core/post-featured-image block needs a "loading" attribute with matching "Loading" options "Default","Disabled","Lazy" and "Eager"? This value can then be passed to get_the_post_thumbnail() overriding the default loading attribute.

Last edited 19 months ago by RavanH (previous) (diff)

This ticket was mentioned in Slack in #core by desrosj. View the logs.

19 months ago

#3 @Bernhard Reiter
19 months ago

  • Component changed from Post Thumbnails to Editor
  • Milestone changed from Awaiting Review to 6.2
  • Version 6.1 deleted

This issue seems to predate the 6.1 cycle, and at this point, we can only fix regressions introduced during that cycle. I'm thus setting the milestone to 6.2.

Also setting the component to Editor, since the issue needs fixing in the Post Featured Image block, which is part of Gutenberg.

#4 @Bernhard Reiter
19 months ago

  • Milestone 6.2 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

@mikeschroder kindly pointed me to #56930. Closing this ticket as a duplicate, per this comment.

Note: See TracTickets for help on using tickets.