Forums

How do I access php variables declared in another section (7 posts)

  1. giant slayer
    Member
    Posted 9 months ago #

    I am trying to access php variables in the footer which are declared in the header. For example, if I declare
    $hello="Hello World!!"; in my header, when I try to make a call to $hello in the footer, it is null or empty.

    Is there a way to access a php variable from one section which was declared in a prior section?

    Thanks!!
    --christopher

  2. esmi
    Theme Diva & Forum Moderator
    Posted 9 months ago #

    Use a function in your theme's functions.php to create these variables and then call the function in each template file as appropriate.

  3. giant slayer
    Member
    Posted 9 months ago #

    Thank you. Can you point me to any simple examples I can study to possibly get me further along?

  4. giant slayer
    Member
    Posted 9 months ago #

    I found a simple article here which helped.
    http://www.themebig.com/94/create-wordpress-functions/

  5. giant slayer
    Member
    Posted 9 months ago #

    One question, how do variables work in relation to include and require?
    If I include or require a file, are the variables of the included file accessible in the functions.php?

  6. esmi
    Theme Diva & Forum Moderator
    Posted 9 months ago #

    Assuming they are global variables, yes.

  7. giant slayer
    Member
    Posted 9 months ago #

    I have been experimenting some, and have learned some things but still have questions.

    I have a variable declared in my head called $user and another called $user_profile. How do I save these variables in a function that I can call in a different section/template file?

    Thanks (and sorry for so many questions)

Reply

You must log in to post.

About this Topic