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'); ?>
}
?>
9 Responses
I am now a fan. This site is going to do very well if it continues to come up with “great recipes”.
@Neowster: Thanks a lot for your kind words, I really appreciate it!
This is cool.
Please tell me also how to make different headers appear randomly or in rotation.
Thanks & ciao
alexander
Oooh, that is so cool. I think I will implement it into one of my wordpress designs!
I’m still a PHP noob, but this was giving me “unexpected <” errors until I stripped out the inline tags. Once I did, things worked perfectly:
What would be the conditional tag if you want a different header for index.php?
Thank you
Trackbacks: