Visual Composer:自定义短代码不起作用

时间:2016-07-05 11:57:37

标签: php wordpress shortcode visual-composer

以下是我在functions.php中创建的短代码:

function echo_first_name() {
    echo $_GET['first_name'];
}
add_shortcode( 'first_name', 'echo_first_name' );

我正在将以下内容输入我的Visual Composer编辑器:

['first_name']

即使使用Visual Composer短代码映射器,也不会产生任何结果。

有人知道为什么这不起作用吗?我是否必须将其注册为Visual Composer的另一种短代码才能访问它?

3 个答案:

答案 0 :(得分:1)

For Create Short code

如果您想在编辑器中添加短代码,请使用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"]

答案 1 :(得分:0)

您正在短信代码函数中传递$ _GET ['firstname'],您可以在此处通过URL或从任何其他位置传递此函数。请检查它是否来了。 或者,如果您想测试您的短代码是否有效,请使用以下代码,它将起作用。

function echo_first_name() {
    return 'testing the shortcode';
}

add_shortcode( 'first_name', 'echo_first_name' );

答案 2 :(得分:0)

使用返回代替回显

function echo_first_name(){
return $_GET['first_name'];
}
add_shortcode( 'first_name', 'echo_first_name' );
相关问题