Passing variables through get_header and get_footer
While working on a integration between a custom shopping cart solution and WordPress I found the get_header() and get_footer() to not correctly with variables and functions I needed to call.
I have two possible solutions:
First solution.
I can include the needed PHP file directly. This is not the preferred method but a solution at this time to pass all the needed strings and variables.
include(TEMPLATEPATH.'/header.php')
Second Solution.
Use variables before get_header(). In index.php, or other template file name you’re using:
<?php $your-variable = the-value; get_header(); ?>
Then in your header:
<?php echo $your-variable; ?>
![[Return to HOME] web design solutions](/images/logo_body.jpg)
I tried the second solution, and it seems is not working with me I don’t know.
I using WordPress 3.0.
But, I tried another thing though I added global before the $your-variable in the header.
as result here whats is looks like in the header.
global $your-variable;
echo $your-variable;
Neither of these variable passing options seem to work if you’re trying to have WP as one part of an existing site structure that utilises a common header & footer over all pages. It’s a catch 22. Either you pour your code into the WP theme’s header & footer files (ie. duplication) or you accept that you can’t have variables passed to your common header & footer files, so you create another set just for WP (ie. duplication).
I think WP didn’t play with the other children very well as a kid. :)
Hello Dave, I will be creating a new post explaining a solution that does work without duplication. It is a little technical but I have been testing it for about a year and it is installed in about 10 websites I have developed. Basically it uses a database table to store the users session and is then retrieved inside WordPress or outside it.