Title: wp_omit_loading_attr_threshold
Published: February 3, 2022
Last modified: February 24, 2026

---

# wp_omit_loading_attr_threshold( bool $force = false ): int

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#wp--skip-link--target)

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#description)󠁿

This function runs the [‘wp_omit_loading_attr_threshold’](https://developer.wordpress.org/reference/hooks/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](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#parameters)󠁿

 `$force`booloptional

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

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#return)󠁿

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

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#source)󠁿

    ```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
    		 * @since 6.3.0 The default threshold was changed from 1 to 3.
    		 *
    		 * @param int $omit_threshold The number of media elements where the `loading` attribute will not be added. Default 3.
    		 */
    		$omit_threshold = apply_filters( 'wp_omit_loading_attr_threshold', 3 );
    	}

    	return $omit_threshold;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/media.php#L6211)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/media.php#L6211-L6231)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_omit_loading_attr_threshold’, int $omit_threshold )](https://developer.wordpress.org/reference/hooks/wp_omit_loading_attr_threshold/)

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

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [wp_get_loading_optimization_attributes()](https://developer.wordpress.org/reference/functions/wp_get_loading_optimization_attributes/)`wp-includes/media.php` |

Gets loading optimization attributes.

  | 
| [wp_get_loading_attr_default()](https://developer.wordpress.org/reference/functions/wp_get_loading_attr_default/)`wp-includes/deprecated.php` |

Gets the default value to use for a `loading` attribute on an element.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_omit_loading_attr_threshold/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_omit_loading_attr_threshold%2F)
before being able to contribute a note or feedback.