setting variable in header.php but not seen in footer.php

后端 未结 5 1189
醉梦人生
醉梦人生 2021-02-19 02:24

in wordpress , i set a variable in header.php


but in footer.php when I ech

5条回答
  •  天涯浪人
    2021-02-19 02:42

    You're not in the same scope, as the header and footer files are included in a function's body. So you are declaring a local variable, and referring to another local variable (from another function).

    So just declare your variable as global:

    $GLOBALS[ 'var' ] = '...';
    

    Then:

    echo $GLOBALS[ 'var' ];
    

提交回复
热议问题