Ok, this is to do with my last question about whether get_header is required for the theme to work.
I’ve looked in wp-includes/general-template.php where function get_header is defined and it does the following things:
do_action( 'get_header' );
- Checks if there is a header.php template file.
- If there is, it includes it
- If there isn’t, it includes one from the default theme
As far as I know, do_action is used to create hooks for plugins to use. So, should I just add the code do_action( 'get_header' );
above my include(TEMPLATEPATH.'/header.php')
?
No, you should use the get_header() function instead of reinventing the wheel. The get_header() function is expected and should always be used. Same as with get_sidebar() and get_footer(). Just because that is what it does now does not mean that that is not subject to change in the future, and so you need to do the right thing in your theme to be forward-compatible.
If this causes you problems, then you need to explain those problems in more detail, so that we can help you solve them. Use of get_header() should not change the get_permalink or get_category_rss_link functions, as those are not Loop functions and they use their own globals.
However, use of get_header will remove access to global vars from the header.php file. This is intentional, if you want to use globals in header.php, you have to declare them as such.
Ok thanks. I think the problem is with global variables rather than the functions.
Thank you, that has solved it.
The problem was that I was defining variables containing page and category IDs in functions.php
(Is this bad practise? Is there a better place to put them?) and I did not know that you could not use global variables in header.php
.
To solve this I added the code <?php global $myvar1, $myvar2, $myvar3; ?>
.
This works, but I am worried that I may still be going about this the wrong way.