V
V
VANY2015-12-15 21:05:15
WordPress
VANY, 2015-12-15 21:05:15

Question for 200 - if you declare a variable in header.php - it will not be called in footer.php?

In general, I declared a variable in header.php, which is included in page.php. In header.php - echo $variable works, in footer.php - no.
Those. Can a variable be declared only within one file? And if you attach files through include - will you see the variables?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivanq, 2015-12-15
@vanyproduction

I think when get_header() is called (or whatever, I don't remember), the code is something like this:

function get_header() {
    include "header.php";
}

The code, of course, is taken at random. Since in php all variables in functions are local by default, the variable is created in the function space and is no longer visible in another function (get_footer). You can try to write in header.php and footer.php code:
<?php global $variable; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question