首页 > 解决方案 > 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)显示为字符串,这不是我需要的。

标签: wordpresswordpress-shortcode

解决方案


要使用 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]');
}

推荐阅读