The MU forums have moved to WordPress.org

Variables initialized in header.php not available later in footer.php? (7 posts)

  1. erick_paper
    Member
    Posted 15 years ago #

    Hi. I have some variables in the header.php of my theme. I imagine that these will be available in the footer.php of the same theme, given how WP works in a sequence. But they're not available in the footer.php. What am I missing?

    Thanks for any pointers.

  2. SteveAtty
    Member
    Posted 15 years ago #

    are they set as global?

  3. erick_paper
    Member
    Posted 15 years ago #

    No. But I tried setting them as global, and they still don't work.

    I have a config.php. I require it into my header.php.

    All variables inside config.php are global now. Still footer.php does not see them.

    Any other ideas? Thx for the response!

  4. SteveAtty
    Member
    Posted 15 years ago #

    and are they marked as global in the footer as well? If you've got code in the footer inside functions then you'll need to flag those variables as global there

  5. cafespain
    Member
    Posted 15 years ago #

    - Header.php -

    global $myvar;
    
    $myvar = "hello";

    - Footer.php -

    global $myvar;
    
    echo $myvar;
  6. SteveAtty
    Member
    Posted 15 years ago #

    How are you putting stuff in your footer?

    I use footer.php in my mu-plugins

    and have this in there:

    function wpmu_footer($blah)
    {
    global $dogooglemap;
    $dogooglemap=0;
    echo '<link rel="search" type="application/opensearchdescription+xml" title="CanalPlan Blogs" href="http://canalplan.blogdns.com/canalblogs.xml" />';
    return $blah;
    }
    add_action('wp_footer', 'wpmu_footer');
  7. charliespider
    Member
    Posted 15 years ago #

    you can also use the php GLOBALS array

    so in your config.php file set

    $GLOBALS['some_key_name'] = 'your_variable';

    then you can access it from anywhere with

    $GLOBALS['some_key_name']

About this Topic

  • Started 15 years ago by erick_paper
  • Latest reply from charliespider