- 插件基础知识
- 插件安全
- 钩子
- 隐私
- 管理菜单
- 简码
- 设置
- 元数据
- 自定义帖子类型
- 分类法
- 用户
-
- JavaScript、Ajax 和 jQuery
- 任务调度
- 国际化
- 插件目录
- 开发人员工具
-
基本简码
添加简码
可以使用简码 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()
.