钩子文档

pre_wp_get_loading_optimization_attributes

💡 云策文档标注

概述

pre_wp_get_loading_optimization_attributes 是一个 WordPress 过滤器,用于控制是否短路加载优化属性的生成过程。开发者可以通过此过滤器返回自定义数组来覆盖默认行为。

关键要点

  • 过滤器名称:pre_wp_get_loading_optimization_attributes
  • 作用:允许开发者短路加载优化属性的生成,返回自定义数组
  • 参数:$loading_attrs(数组或 false,默认 false)、$tag_name(字符串)、$attr(数组)、$context(字符串)
  • 返回值:返回数组将短路并替换默认加载优化属性
  • 引入版本:WordPress 6.4.0
  • 相关函数:wp_get_loading_optimization_attributes()

代码示例

$loading_attrs = apply_filters( 'pre_wp_get_loading_optimization_attributes', false, $tag_name, $attr, $context );

📄 原文内容

Filters whether to short-circuit loading optimization attributes.

Description

Returning an array from the filter will effectively short-circuit the loading of optimization attributes, returning that value instead.

Parameters

$loading_attrsarray|false
False by default, or array of loading optimization attributes to short-circuit.
$tag_namestring
The tag name.
$attrarray
Array of the attributes for the tag.
$contextstring
Context for the element for which the loading optimization attribute is requested.

Source

$loading_attrs = apply_filters( 'pre_wp_get_loading_optimization_attributes', false, $tag_name, $attr, $context );

Changelog

Version Description
6.4.0 Introduced.