wp_omit_loading_attr_threshold() WordPress Function

The wp_omit_loading_attr_threshold() function is used to determine when the loading="lazy" attribute should be added to images. By default, this function will add the loading="lazy" attribute to images that are larger than 1MB in size.

wp_omit_loading_attr_threshold( bool $force = false ) #

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 1. The filter is only run once per page load, unless the $force parameter is used.


Top ↑

Parameters

$force

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

Default value: false


Top ↑

Return

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


Top ↑

Source

File: wp-includes/media.php

function wp_omit_loading_attr_threshold( $force = false ) {
	static $omit_threshold;

	// This function may be called multiple times. Run the filter only once per page load.
	if ( ! isset( $omit_threshold ) || $force ) {
		/**
		 * Filters the threshold for how many of the first content media elements to not lazy-load.
		 *
		 * For these first content media elements, the `loading` attribute will be omitted. By default, this is the case
		 * for only the very first content media element.
		 *
		 * @since 5.9.0
		 *
		 * @param int $omit_threshold The number of media elements where the `loading` attribute will not be added. Default 1.
		 */
		$omit_threshold = apply_filters( 'wp_omit_loading_attr_threshold', 1 );
	}

	return $omit_threshold;
}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More