return $postprocess( $loading_attrs, true
);
} } /*
* The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded,
* as they are likely above the fold. Shortcodes are processed after content images, so if
* thresholds haven't already been met, apply the same logic to those as well.
*/
if ( 'the_content' ===
$context || 'the_post_thumbnail' ===
$context || 'do_shortcode' ===
$context ) { // Only elements within the main query loop have special handling.
if ( is_admin() || !
in_the_loop() || !
is_main_query() ) { $loading_attrs['loading'
] = 'lazy';
return $postprocess( $loading_attrs, false
);
} // Increase the counter since this is a main query content element.
$content_media_count =
wp_increase_content_media_count();
// If the count so far is below the threshold, `loading` attribute is omitted.
if ( $content_media_count <=
wp_omit_loading_attr_threshold() ) { // The first largest image will still get `fetchpriority='high'`.
return $postprocess( $loading_attrs, true
);
}