// Conditionally skip lazy-loading on images before the loop.
if ( // Only apply for main query but before the loop.
$wp_query->before_loop &&
$wp_query->
is_main_query() /*
* Any image before the loop, but after the header has started should not be lazy-loaded,
* except when the footer has already started which can happen when the current template
* does not include any loop.
*/
&&
did_action( 'get_header'
) && !
did_action( 'get_footer'
) ) { return false;
} } /*
* 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.