视觉作曲:自定义简码不工作
问题描述:
以下是我的functions.php创建的简码:视觉作曲:自定义简码不工作
function echo_first_name() {
echo $_GET['first_name'];
}
add_shortcode('first_name', 'echo_first_name');
而且我输入下面我的可视化编辑器编辑:
['first_name']
这即使使用Visual Composer短代码映射器也不会产生结果。
有人知道为什么这不起作用吗?我是否必须将其注册为Visual Composer能够访问的另一种短代码类型?
答
,如果你想在编辑器中添加的然后用来代替return
echo
function echo_first_name() {
return $_GET['first_name'];
}
add_shortcode('first_name', 'echo_first_name');
使用短代码短代码就像
[first_name]
If you want to pass the value In shortcode
function echo_first_name($atts) {
$a = shortcode_atts(array(
'firstname' => '',
), $atts);
return "First Name= {$a['firstname']}";
}
add_shortcode('first_name', 'echo_first_name');
使用短代码就像
[first_name firstname="test"]
答
您正在通过网址或其他任何地方传递此代码的短代码函数中传递$ _GET ['firstname']。请检查它是否即将到来。 或者如果你想测试你的短代码是否正在使用beloww代码它将工作。
function echo_first_name() {
return 'testing the shortcode';
}
add_shortcode('first_name', 'echo_first_name');
答
使用回报代替呼应
function echo_first_name(){
return $_GET['first_name'];
}
add_shortcode('first_name', 'echo_first_name');
在你短代码中使用return代替echo –
并使用短代码,如[first_name]不加引号 –
@AnkurBhadania非常感谢!我在其他地方找不到任何相关答案。它如何才能在我使用return时起作用? –