2017-08-11 1 views
1

WordPressのショートコードを使用して任意のページにPHP変数値をエコーし​​たいとします。WordPressのショートコードを使用してPHP変数をエコーする

私が作成している:私はどのページにショート[test]を置くと

function custom_shortcode() { 

    echo $unique; 

} 
add_shortcode('test', 'custom_shortcode'); 

を、それは何も返しません。

$unique変数は、ログインしているユーザーのユーザー名をURLに表示するための変数です。たとえば、次のようにフロントエンドにexample.com/?username

期待される出力は次のようにする必要があります:example.com/?username

答えて

1

はこれを試してみてください。

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

おかげ@aidinMC – Chandrakant

関連する問題