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 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

share|improve this question
up vote 8 down vote accepted

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();

share|improve this answer
this worked out, thanks. I didn't realise initialising the var with global was required... do you have a reference article for that by any chance? – jammypeach Dec 21 '11 at 16:24
This is a nice write up thewebsqueeze.com/web-design-tutorials/… – Bainternet Dec 21 '11 at 16:28

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.