添加短代码
可以使用短代码 API 添加自己的短代码。该过程涉及使用 add_shortcode() 将回调函数 $func 注册到短代码 $tag。
add_shortcode(
string $tag,
callable $func
);[wporg] 是你的新短代码。使用短代码将触发 wporg_shortcode 回调函数。
add_shortcode('wporg', 'wporg_shortcode');
function wporg_shortcode( $atts = [], $content = null) {
// do something to $content
// always return
return $content;
}移除短代码
可以使用短代码 API 移除短代码。该过程涉及使用 remove_shortcode() 移除已注册的 $tag。
remove_shortcode(
string $tag
);在尝试移除之前,请确保短代码已注册。为 add_action() 指定较高的优先级数字,或挂钩到稍后运行的操作钩子。
检查短代码是否存在
要检查短代码是否已注册,请使用 shortcode_exists()。