4

I have a var set in my header.php file:

$myBool = false;

and in page.php, I try to echo it:

echo $myBool;

But the variable is never set. This doesn't help either:

global $myBool;
echo $myBool;

Does anyone know what the problem is?

Note: I'm using a custom theme based on the blank theme ( http://digwp.com/2010/02/blank-wordpress-theme/ ) but the same behaviour is evident when using twentyten / eleven so the theme seems to have nothing to do with this

8

You need to globalize it before you set the value, so in your header.php

global $myBool;
$myBool = false;

and then in your page.php

global $myBool;
echo $myBool;

just make sure you page.php includes the header.php file either directly or by calling get_header();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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