wp_omit_loading_attr_threshold

函式
wp_omit_loading_attr_threshold ( $force = false )
引數
  • (bool) $force Optional. If set to true, the filter will be (re-)applied even if it already has been before. Default false.
    Required:
    Default: false
返回值
  • (int) The number of content media elements to not lazy-load.
定義位置
相關方法
wp_get_loading_attr_defaultwp_img_tag_add_loading_attrwp_iframe_tag_add_loading_attrwp_lazy_loading_enabledwp_admin_bar_header
引入
5.9.0
棄用
-

wp_omit_loading_attr_threshold。這個過濾器用於設定省略img標籤中載入屬性的閾值。它用於通過減少需要載入的資料量來提高頁面的效能。

獲取不懶惰載入的第一個內容媒體元素的閾值。

這個函式執行{@see ‘wp_omit_loading_attr_threshold’}過濾器,它使用一個預設的閾值1。除非使用`$force`引數,否則每個頁面載入時只執行一次過濾器。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >