shortcode_exists()
云策文档标注
概述
shortcode_exists() 函数用于检查指定名称的短代码是否已在 WordPress 中注册。它基于全局变量 $shortcode_tags 进行判断,返回布尔值。
关键要点
- 参数 $tag 为字符串类型,必需,表示要检查的短代码标签。
- 返回值为布尔类型,指示给定短代码是否存在。
- 函数内部使用 array_key_exists() 检查 $tag 是否在全局数组 $shortcode_tags 中。
- 该函数自 WordPress 3.6.0 版本引入。
代码示例
function shortcode_exists( $tag ) {
global $shortcode_tags;
return array_key_exists( $tag, $shortcode_tags );
}
原文内容
Determines whether a registered shortcode exists named $tag.
Parameters
$tagstringrequired-
Shortcode tag to check.
Source
function shortcode_exists( $tag ) {
global $shortcode_tags;
return array_key_exists( $tag, $shortcode_tags );
}
Changelog
| Version | Description |
|---|---|
| 3.6.0 | Introduced. |
Skip to note 2 content
Codex
Basic Example