How to: Use multiple custom headers on a WordPress theme

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

Oct 21 2008 15:07

I am now a fan. This site is going to do very well if it continues to come up with “great recipes”.

Oct 21 2008 15:44

@Neowster: Thanks a lot for your kind words, I really appreciate it! :)

Oct 22 2008 07:30

This is cool.

Please tell me also how to make different headers appear randomly or in rotation.

Thanks & ciao
alexander

Oct 23 2008 06:15

Oooh, that is so cool. I think I will implement it into one of my wordpress designs!

Dec 14 2008 02:25

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:

Feb 22 2009 21:31

What would be the conditional tag if you want a different header for index.php?

Thank you

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required
Blog And Make Cash