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'); ?>
}
?>

Related Posts

Related Posts

No related posts.

7 Responses

Aug 28 2011 01:32

Actually you need to remove your “” after the semi-colon “;” for the above script to work. Other than that, it’s flawless. Thanks!

Aug 28 2011 01:35

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.

Sep 15 2011 07:51

Yes need to remove php starting and ending tag in include line like

include(TEMPLATEPATH.’/headercontact.php’);

Sep 30 2011 14:44

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

Oct 26 2011 02:55

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 :)

Dec 07 2011 08:30

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’);

Jan 05 2012 21:16

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:

Leave a Comment

* Name, Email, Comment are Required