函数文档

wp_high_priority_element_flag()

💡 云策文档标注

概述

wp_high_priority_element_flag() 函数用于访问或设置一个静态标志,指示元素是否为 fetchpriority='high' 的候选者。它通过布尔值参数控制标志状态,并返回当前标志值。

关键要点

  • 函数 wp_high_priority_element_flag() 管理一个静态布尔变量 $high_priority_element,默认值为 true。
  • 接受可选参数 $value(布尔类型),用于设置标志值;若未提供参数,则返回当前标志值。
  • 返回布尔值:true 表示元素已被标记为高优先级,false 表示未标记。
  • 与 wp_maybe_add_fetchpriority_high_attr() 函数关联,用于确定是否添加 fetchpriority='high' 属性。
  • 自 WordPress 6.3.0 版本引入。

代码示例

function wp_high_priority_element_flag( $value = null ) {
    static $high_priority_element = true;

    if ( is_bool( $value ) ) {
        $high_priority_element = $value;
    }

    return $high_priority_element;
}

📄 原文内容

Accesses a flag that indicates if an element is a possible candidate for fetchpriority='high'.

Parameters

$valuebooloptional
Used to change the static variable.

Default:null

Return

bool Returns true if high-priority element was marked already, otherwise false.

Source

function wp_high_priority_element_flag( $value = null ) {
	static $high_priority_element = true;

	if ( is_bool( $value ) ) {
		$high_priority_element = $value;
	}

	return $high_priority_element;
}

Changelog

Version Description
6.3.0 Introduced.