基本简码

添加简码

可以使用简码 API 添加您自己的简码。该过程涉及使用注册回调$func到简码。$tag``add_shortcode()

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 删除简码。$tag该过程涉及使用remove_shortcode()删除注册。

remove_shortcode(
    string $tag
);

在尝试删除之前,请确保已注册简码。为add_action()指定更高的优先级数字 或挂接到稍后运行的操作挂钩。

检查简码是否存在

要检查简码是否已注册,请使用shortcode_exists().