DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

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

23 Comments

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

  2. 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.

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

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

  4. 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

  5. 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 🙂

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

  7. 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**

  8. Why not use the example from the wordpress codex:

    Just customise as needed – header templates should be saved as header-name.php

  9. I agree with David, you should use the get_header function instead of include:

    if ( is_home() ) :
    get_header(‘home’);

  10. Hello, thank you for all your comments,

    But I try to use multy custom headers and I can’t do it !!!

    I don’t know how exactly to whrite the code :

    I want to custom my contact page, his name is : pagecontact.php
    I have already create a custom header for this page : headercontact.php

    and i don’t know where to put it ?

    just on the page I want to custom ? the contact page ?
    On the index page also ?
    on the header page ?

    If somewhone can help me it’s will be so great
    thanks a lot
    Delphine

  11. Hello Delphine,

    Just change your headercontact.php to header-contact.php

    and then change the get_header(); called at very top of pagecontact.php to
    get_header(‘contact’);

    Hope this helps.

  12. Totally agree with David Woodthorpe. We should use get_header(‘blog’) for blog category. It works well for me.

  13. Is there a way to extend this conditional header for each of the main sections of the site AND its child pages? So for “About” there is one header and any page under that About section has the same header?

  14. Anyone getting multiple headers I don’t know how to remove the original header

  15. Hi all, I’m new to WordPress but am considering using it for my website rather than pay for a host provider. I really would like to have a custom header for each page like you all are talking about, but I have NO idea where to put this php code… I only have a free wordpress page right now. Do I have to upgrade to the “customize” package so I can make these edits? Otherwise, when I create a new page, I can’t tell where to put the code…
    Thanks so much for your time and help!

  16. Hi,

    Here’s how I do it:

    1. Install the Custom Post Template plugin.
    2. Open the page.php or post.php file of your theme and save a copy of it as page-my-pic1.php.
    3. Enter the following code on top of this file:

    4. Copy your header file and rename it to say header-my-pic1.php

    Make relevant changes in this header file (+ any other css files etc) to include your desired pic.

    5. Now type the following code in the file (beneath the above code) that we earlier created i.e page-my-pic1.php

    Upload all the files along with your pic1 etc.

    6. Open the page where you want the desired pic on the header. Under Page Attributes you’ll have a Template drop down.

    Select My Pic1 Template.

    There you have it. Although this process is a bit long but I love it as it gives me the freedom to change pics on the click of a button. You can also use it to apply any other kind of changes to a particular post or page.

  17. Sorry the code didn’t appear above perhaps due to php tags:

    Here it’s again:

    code for point 3:

    First it must be Inside php tags and it must be commented using php comments tag.:
    /*
    Template Name: My Pic1 Template
    */

    Code for point 5: (It must also be inside php tags)

    get_header(‘my-pic1’);

  18. Man, you really save my life!
    Thanks so much!

  19. I did this and lost all CSS settings on the page…

  20. This is not working for me. It default to the last one. It I place the page name in it fails. Any Idea why?

  21. That’s not a bad solution if you only need a few different header images but what if you want heaps?

    So much easier to use a custom field and meta box using a plugin like ACF than multiple if statements

  22. Are you sure this is not going to effect plugins? Many plugins “hook” into your header.php file. But you have completely stripped out the content of that file and just replaced it with includes to other files?

Leave a Comment

Your email address will not be published. Required fields are marked *