1

以下是我在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 才能访问它?

4

3 回答 3

1

对于创建短代码

如果您想在编辑器中添加短代码,则使用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"]
于 2016-07-05T12:41:57.597 回答
0

您在短代码函数中传递了一个 $_GET['firstname'] ,从您在 URL 中传递它的地方或从任何其他地方传递。请检查它是否即将到来。或者,如果您想测试您的简码是否正常工作或不使用下面的代码,它将工作。

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

add_shortcode( 'first_name', 'echo_first_name' );
于 2016-07-05T12:35:47.430 回答
0

使用return而不是echo

function echo_first_name(){
return $_GET['first_name'];
}
add_shortcode( 'first_name', 'echo_first_name' );
于 2016-11-16T07:54:21.087 回答