Global variables not accessible from theme files
-
Hello, I am trying to integrate bbPress seamlessly into my custom WordPress theme. However, this theme defines several global variables which are then used by the theme files.
These variables are defined as global variables in header.php of the wordpress theme and are used without problems in all theme files. Example:
header.php
global $variable;
$variable = "value";single.php
global $variable;
echo $variable; // outputs "value" as it should
So far, so good. But if I try to use the variable in a bbPress theme file, it is empty:
content-single-topic.php
global $variable;
echo $variable; // outputs ""When bbPress is done, the variable comes back to life:
loop-single.php
echo $variable; // outputs "value" as it should
the_content(); // all the bbPress stuff, $variable empty – what happens there?
echo $variable; // outputs "value" againUsing print_r($GLOBALS), it turns out that in fact all the custom variables cease to exist for the time bbPress is doing its job and than come back to life.
How can I pass a global value to the bbPress theme files without doing absurd things like querying the database?
- You must be logged in to reply to this topic.