繁体   English   中英

Visual Composer:自定义简码不起作用

[英]Visual Composer: Custom Shortcode Not Working

以下是我在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的另一种短代码才能访问它?

对于创建短代码

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

您正在通过URL或其他任何地方在shortcode函数中传递$ _GET ['firstname']。 请检查它是否来了。 或者,如果您想测试您的短代码是否正常工作,或者不使用beloww代码,那么它将起作用。

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

add_shortcode( 'first_name', 'echo_first_name' );

使用return代替echo

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM