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

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

    I know this is a bit old question and with a solution voted but I though I should share another option and just found a better solution (that works) without using Globals

    function fn_your_var_storage( $var = NULL )
    {
        static $internal;
    
        if ( NULL !== $var )
        {
            $internal = $var;
        }
    
        return $internal;
    }
    
    // store the value
    fn_your_var_storage( 'my_value' );
    
    // retrieve value
    echo fn_your_var_storage(); // print my_value
    

提交回复
热议问题