wp_omit_loading_attr_threshold( bool $force = false ): int

In this article

Gets the threshold for how many of the first content media elements to not lazy-load.

Description

This function runs the ‘wp_omit_loading_attr_threshold’ filter, which uses a default threshold value of 3.
The filter is only run once per page load, unless the $force parameter is used.

Parameters

$forcebooloptional
If set to true, the filter will be (re-)applied even if it already has been before.

Default:false

Return

int The number of content media elements to not lazy-load.

Source

 * The key function logic starts here.
 */
$maybe_in_viewport    = null;
$increase_count       = false;
$maybe_increase_count = false;

// Logic to handle a `loading` attribute that is already provided.
if ( isset( $attr['loading'] ) ) {
	/*
	 * Interpret "lazy" as not in viewport. Any other value can be
	 * interpreted as in viewport (realistically only "eager" or `false`
	 * to force-omit the attribute are other potential values).
	 */
	if ( 'lazy' === $attr['loading'] ) {
		$maybe_in_viewport = false;
	} else {
		$maybe_in_viewport = true;
	}
}

// Logic to handle a `fetchpriority` attribute that is already provided.

Changelog

VersionDescription
5.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.