wordpress - Wordpress 短代码返回带有短代码的 html 字符串
问题描述
我制作了一个返回字符串的短代码,该字符串应该显示为 html。问题是这个 html 字符串还应该包含用于格式化页面的短代码。意义:
add_shortcode('my_shortcode','my_function');
function my_function(){
return ' [vc_column width="1/2"] <h1>This is my content between the shortcodes</h1> [/vc_column]';
}
我怎么能在页面上显示这个?如果我只是在简码块中添加 [my_shortcode],它会将这些返回的简码(vc_column)显示为字符串,这不是我需要的。
解决方案
要使用 PHP 显示短代码,您需要使用该函数do_shortcode
。
您需要执行以下操作:
function my_function(){
return do_shortcode('[vc_column width="1/2"] <h1>This is my content between the shortcodes</h1> [/vc_column]');
}
推荐阅读
- php - 一个 WordPress 循环,仅显示 4 个类别的最新帖子
- reactjs - 如何将我的 material-ui 主题暴露给控制台,如 material-ui 站点?
- php - 获取选定元素及其子元素的数组
- python - 如何使用 Python CSV Writer 保留尾随零
- java - 使用新参数重复 WebClient 获取
- javascript - 我正在构建一个答题器游戏,而 localstorage 什么都没有返回,而不是保存的数据
- mysql - 使用连接忽略选择中的表列值
- c - 如何从 int 变量中提取字节(存储在 int 变量中的十六进制值)?
- android - 实施 Admob 广告依赖的问题
- composer-php - 防止生产环境中的作曲家更新