• OK…

    I have made a static page (page-index.php), and am loading a my header (header.php) via the standard <?php get_header(); call.

    I have defined a variable in ‘page-index.php’ that I would like to use in a function located in ‘header.php’. Once again, header.php is loaded into ‘page-index.php’.

    I have noticed that in wordpress, unless the variable is defined, and used in the same page…the value doesn’t stick…even if the second page (in my case, the header) is loaded by include.

    I mean..wtf…any suggestions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • If you define a global variable and attempt to use it in a function you need to tell the function to use the global value of that variable. Here is an example of setting a variable:

    $var1 = "test";

    Now if i want to use it in function func_a on a different page it wuold look something like this:

    function func_a(){
      global $var1;
    
      echo $var1;
    }

    That global statement will tell it to make the global variable available in that function

    [signature moderated Please read the Forum Rules]

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Variables – assistance’ is closed to new replies.