钩子文档

wp_lazy_loading_enabled

💡 云策文档标注

概述

wp_lazy_loading_enabled 是一个 WordPress 过滤器,用于控制是否向指定标签在指定上下文中添加 loading 属性,以实现懒加载功能。它允许开发者根据标签名称和上下文动态启用或禁用懒加载。

关键要点

  • 过滤器名称:wp_lazy_loading_enabled
  • 参数:$default(布尔值,默认值)、$tag_name(字符串,标签名)、$context(字符串,上下文信息)
  • 返回值:布尔值,决定是否添加 loading 属性
  • 引入版本:WordPress 5.5.0
  • 相关函数:wp_lazy_loading_enabled() 位于 wp-includes/media.php

代码示例

add_filter( 'wp_lazy_loading_enabled', '__return_false' );

注意事项

用户反馈指出,在 WordPress 5.9 版本中,使用 add_filter( 'wp_lazy_loading_enabled', '__return_false' ) 可能不再有效,建议检查最新文档或更新代码。


📄 原文内容

Filters whether to add the loading attribute to the specified tag in the specified context.

Parameters

$defaultbool
Default value.
$tag_namestring
The tag name.
$contextstring
Additional context, like the current filter name or the function name from where this was called.

Source

return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context );

Changelog

Version Description
5.5.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    To disable lazy loading use:

    add_filter( 'wp_lazy_loading_enabled', '__return_false' );