/*
* The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded,
* as they are likely above the fold.
*/
if ( 'the_content' ===
$context || 'the_post_thumbnail' ===
$context ) { // Only elements within the main query loop have special handling.
if ( is_admin() || !
in_the_loop() || !
is_main_query() ) { return 'lazy';
} // 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, return `false` so that the `loading` attribute is omitted.
if ( $content_media_count <=
wp_omit_loading_attr_threshold() ) { return false;
} // For elements after the threshold, lazy-load them as usual.
return 'lazy';
} // Lazy-load by default for any unknown context.