Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在WordPress中使用快捷码回显PHP变量_Php_Wordpress_Shortcode - Fatal编程技术网

在WordPress中使用快捷码回显PHP变量

在WordPress中使用快捷码回显PHP变量,php,wordpress,shortcode,Php,Wordpress,Shortcode,我想使用WordPress中的快捷码在任何页面上回显PHP变量值 我创造了: function custom_shortcode() { echo $unique; } add_shortcode( 'test', 'custom_shortcode' ); 当我在任何页面上放置shortcode[test]时,它不会返回任何内容 $unique变量用于在URL中显示登录用户的用户名。例如:example.com/?username 前端的预期输出需要是:example.com/?

我想使用WordPress中的快捷码在任何页面上回显PHP变量值

我创造了:

function custom_shortcode() {

    echo $unique;

}
add_shortcode( 'test', 'custom_shortcode' );
当我在任何页面上放置shortcode
[test]
时,它不会返回任何内容

$unique
变量用于在URL中显示登录用户的用户名。例如:
example.com/?username

前端的预期输出需要是:
example.com/?username

尝试以下操作:

function custom_shortcode( $atts, $content = null )  {
    global $unique; // if $unique is global var add this line too
    return $unique;
}
add_shortcode( 'test', 'custom_shortcode' );