在WordPress中使用快捷码回显PHP变量
我想使用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/?
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' );