Customized Global Variables for WordPress

customized global variable, wordpress

Wanted to have one place for certain set of value in my WP site, after many failures, found this to be the easiest way.

In functions.php, define and initialize a variable:

$GLOBALS['your_var'] = 42;

To access the variable in a template file (between php tags):

echo $GLOBALS['your_var']