通知短信+运营短信,5秒速达,支持群发助手一键发送🚀高效触达和通知客户 广告
##添加一个短码 可以使用Shortcode API添加自己的短码。 该过程包括使用add_shortcode()将一个回调$ func注册到一个shortcode $标签。 ``` <?php add_shortcode( string $tag, callable $func ); ``` ## 在一个主题 ``` <?php function wporg_shortcode($atts = [], $content = null) { // do something to $content // always return return $content; } add_shortcode('wporg', 'wporg_shortcode'); ``` [wporg]是您的新短码。 使用短代码将触发wporg_shortcode回调函数。 ##在插件中 与主题不同,插件在加载过程的早期阶段运行,因此要求我们推迟添加我们的短代码,直到WordPress初始化为止。 我们建议使用init动作钩子。 ``` <?php function wporg_shortcodes_init() { function wporg_shortcode($atts = [], $content = null) { // do something to $content // always return return $content; } add_shortcode('wporg', 'wporg_shortcode'); } add_action('init', 'wporg_shortcodes_init'); ``` ##删除一个短码 可以使用Shortcode API来删除短码。 该过程涉及使用remove_shortcode()删除已注册的$标签。 ``` <?php remove_shortcode( string $tag ); ``` 尝试删除之前,请确保已经注册了该短码。 为add_action()指定较高优先级的数字,或者挂钩到稍后运行的动作钩子。 ##检查短码是否存在 检查一个短码是否已经注册使用shortcode_exists()。