How to use the own php variables in the wordpress template?


I am using a wordpress template in php like this:


...Hello World...

<?php get_footer(); ?>

ok, it works good... but the contents of title and other meta tags are empty. How can I change the header contents or use my own $variables inside the get_header() section? it doesnt work like this:


.. inside a wordpress header template:
echo $test;

the $test variable is empty :(.. any ideas? thanks!

The $test variable is empty because the header is included by a function, hence effectively 'in' the function, and more importantly, in a different scope.. think of it like

function get_header()
  $test = '1234';
echo $test; // won't work because test is in a different scope

you can however use globals, or $_SESSION variables, or create a static class to hold variables in that can be called from anywhere.

the global option is probably the quickest fix here (not necessarily the strictest though).

$GLOBALS['test'] = "Blabla";

.. inside a wordpress header template:
echo $GLOBALS['test'];

hope that helps