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

后端 未结 5 1326
醉梦人生
醉梦人生 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:47

    try this code

    first define your initial variable

      $var="something";
    

    then use the $_GLOBALS

      $_GLOBALS['myvar']=$var;
    

    and finally use the global variable in anywhere you want

      global $myvar;
    

    define string inside the $_GLOBALS as taken as global variable name or use the $_GLOBALS['myvar'] direct into the code without using the global

提交回复
热议问题