In wordpress, it calls header.php then whatever template name or the page requested. How can I declare a variable in my php header which I can then refer to in my other templates?
In wordpress, it calls header.php then whatever template name or the page requested. How
Share
The answer pretty much depends what you need it for. If you are developing a theme and want to keep values constant through all files you can place them in
functions.phpin the theme directory, which is always loaded. Variables defined there should be available everywhere in the theme. This works if you distribute the theme.If you want to modify an existing theme for your needs on your own installation, you can either put them in
wp-config.php, as suggested, or (a cleaner method) you can create a child theme of the theme you want to change. This will keep it separate from the wordpress core and will prevent theme updates from overwriting your changes.I just tried it using
functions.php:functions.php:
header.php:
works for me.