wp_lazy_loading_enabled

函式
wp_lazy_loading_enabled ( $tag_name, $context )
引數
  • (string) $tag_name The tag name.
    Required:
  • (string) $context Additional context, like the current filter name or the function name from where this was called.
    Required:
返回值
  • (bool) Whether to add the attribute.
定義位置
相關方法
wp_maybe_load_embedswp_revisions_enabledwp_media_upload_handlerwp_omit_loading_attr_thresholdwp_load_image
引入
5.5.0
棄用
-

wp_lazy_loading_enabled: 該函式檢查當前WordPress安裝中是否啟用了懶人載入功能。

決定是否在指定的上下文中為指定的標籤新增`loading`屬性。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_lazy_loading_enabled( $tag_name, $context ) {
// By default add to all 'img' and 'iframe' tags.
// See https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-loading
// See https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe-loading
$default = ( 'img' === $tag_name || 'iframe' === $tag_name );
/**
* Filters whether to add the `loading` attribute to the specified tag in the specified context.
*
* @since 5.5.0
*
* @param bool $default Default value.
* @param string $tag_name The tag name.
* @param string $context Additional context, like the current filter name
* or the function name from where this was called.
*/
return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context );
}
function wp_lazy_loading_enabled( $tag_name, $context ) { // By default add to all 'img' and 'iframe' tags. // See https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-loading // See https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe-loading $default = ( 'img' === $tag_name || 'iframe' === $tag_name ); /** * Filters whether to add the `loading` attribute to the specified tag in the specified context. * * @since 5.5.0 * * @param bool $default Default value. * @param string $tag_name The tag name. * @param string $context Additional context, like the current filter name * or the function name from where this was called. */ return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context ); }
function wp_lazy_loading_enabled( $tag_name, $context ) {
	// By default add to all 'img' and 'iframe' tags.
	// See https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-loading
	// See https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe-loading
	$default = ( 'img' === $tag_name || 'iframe' === $tag_name );

	/**
	 * Filters whether to add the `loading` attribute to the specified tag in the specified context.
	 *
	 * @since 5.5.0
	 *
	 * @param bool   $default  Default value.
	 * @param string $tag_name The tag name.
	 * @param string $context  Additional context, like the current filter name
	 *                         or the function name from where this was called.
	 */
	return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context );
}

常見問題

FAQs
檢視更多 >