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`参数,否则每个页面加载时只运行一次过滤器。

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
查看更多 >