WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I added a variable to my functions.php file:

$options = get_option( 'simple_options' );

I can access to this variable on every page, but If I call it in the footer.php it's not working. How to fix that?

share|improve this question
up vote 1 down vote accepted

Generally, you cannot access local variables in a function from outside the function, so this...

function func() {
    $var = 2;

$var = 1;
echo $var;

would result in "1".

To make a global variable, you can do this to make $option available outside functions.php:

function func() {
    global $option;
    $option = get_option( 'simple_options' );

However, I cannot recommend it, since every other script may change the value. You can use a define:

define('MY_OPTION',get_option( 'simple_options' );

And in your footer:

echo MY_OPTION; // note that there are no quotation marks

But also this wouldn't be that neat, since you'd have to make sure no other script defines this MY_OPTION and you cannot change it later on.

No, your best bet is to get the option just again in your footer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.