In wordpress , I set a variable in header.php
but in footer.php when I echo it
I got no thing printed. why?
Solution for : setting variable in header.php but not seen in footer.php
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:
Then you can echo it globally.
1 | $var = 'anything' ; |
1 | echo $var ; |
Solution for : setting variable in header.php but not seen in footer.php
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:
1 | $GLOBALS [ 'var' ] = '...' ; |
1 | echo $GLOBALS [ 'var' ]; |
No comments:
Post a Comment