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?

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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