• In a theme I’m currently working on, before get_header() I’ve been putting a variable to change the stylesheet and title of the page (at the moment, $category). Inside header.php, to use $category, I have it set to echo $category at the stylesheet and title tags… except when it echos $category it doesn’t output anything. The variable is blank.

    As an experiment, to make sure the variable wasn’t being completely wiped, I echoed the $category variable directly after get_header() and it worked fine. I also tried directly grabbing header.php with include() and it worked fine in that case too. It’s just not working at all for get_header(). Does anyone have a fix or way to resolve this without just including header.php manually?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Yep, I’m having this same problem as well. Anybody yet figure out a way around this?

    You want to scope your variables to global if using them across templates (or functions, or what have you).

    For those new to PHP, what I mean by “scope to global” is to define the variable as a global one before you assign it a value, or make use of it in any way:

    global $myvar;
    $myvar = 'This is a global variable';

    and:

    global $myvar;
    echo $myvar;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Variables not working in get_header’ is closed to new replies.