WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get_header include (4 posts)

  1. mohrd
    Member
    Posted 3 years ago #

    Hi.
    Does get_header() include header.php content to the page?
    similar php include('header.php')?
    because, I wrote in header.php:
    <?php $abcd = "1234" ?>
    then wrote in index.php:

    <?php
    get_header();
    echo $abcd;
    ?>

    now in index page, I should see $abcd value ("1234"), but i can't see it! and the $abcd is undefined in index.php .

    Why?
    and how can I solve that problem?

    Thanks (sorry for bad English)

  2. simplistik
    Member
    Posted 3 years ago #

    add <?php global $abcd; ?> before you define $abcd

  3. mohrd
    Member
    Posted 3 years ago #

    thanks.
    but why wordpress needs global?

  4. simplistik
    Member
    Posted 3 years ago #

    To be honest I'm not sure. It's isolated to the front end of WordPress. I used to encounter this issue a lot, and that's the only way I know to fix it. I know that the function that gets used inside of the get_header() function is a require_once() but it's still strange none-the-less.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags