Do you ever wanted to have multiple headers on your WordPress blog? If yes, here’s a clear and concise tutorial that will help you to get themost out of your blog headers!
Do you ever wanted to have multiple headers on your WordPress blog? If yes, here’s a clear and concise tutorial that will help you to get themost out of your blog headers!
The first thing to do is to create header files. Create as many different headers as you want. In this exemple, I have created 3 custom headers from my theme default file header.php, names headercontact.php, headergallery.php and headerdefault.php.
By using the php include() function and WordPress conditional tags, we can define custom headers easily.
Replace the content of your header.php file with the following code:
<?php
if (is_page('contact')){
<?php include(TEMPLATEPATH.'/headercontact.php'); ?>
}
elseif (is_page('gallery')){
<?php include(TEMPLATEPATH.'/headergallery.php'); ?>
}
else {
<?php include(TEMPLATEPATH.'/headerdefault.php'); ?>
}
?>
7 Responses
Actually you need to remove your “” after the semi-colon “;” for the above script to work. Other than that, it’s flawless. Thanks!
Great, it stripped it from my comment. Ok, here’s trying to explain it in layman’s terms…
In order to make the above work, you have to remove the php open tag and the php close tag that are in front of each include statement and after each semi-colon respectively.
Yes need to remove php starting and ending tag in include line like
include(TEMPLATEPATH.’/headercontact.php’);
Looks really great but should be written as
if (is_page(‘contact’)){
(TEMPLATEPATH.’/headercontact.php’);
}
elseif (is_page(‘gallery’)){
(TEMPLATEPATH.’/headergallery.php’);
}
else {
(TEMPLATEPATH.’/headerdefault.php’);
With the appropriate PHP wrapper
How would I do this if I want only the home page to have a different header? It is set to blog not static page btw. Thanks
This is what I used to display a custom stylesheet and it worked great. You could probably substitute my wp_enqueue_style with (TEMPLATEPATH.’headername.php’);
Unfortunately your code didn’t work for me, instead I used the following (which did the trick):
if (is_page(‘contact’)){
include(TEMPLATEPATH.’/headercontact.php’);}
elseif (is_page(‘gallery’)){
include(TEMPLATEPATH.’/headergallery.php’);}
else {
include(TEMPLATEPATH.’/headerdefault.php’);}
**Remember to add PHP wrap**
Trackbacks: