I need to create a variable that can be accessed throughout my WordPress Theme template files (index.php, header.php etc..). I know function definitions go inside the functions.php
template file (in your theme path), but there's no such thing for variables.
For example I constantly need to retrieve Categories in my Theme, so I would like to have this accessible from anywhere in my theme:
$categories = get_categories(); /* get_categories() is a wordpress function */
This way I can simply access to allocated data, without having to re-allocate it every time I need to get my categories.
Unfortunately adding that piece of code in my functions.php
file, doesn't work, neither does making the variable global
.