How to use different header for categories and pages in WordPress

wordpress tips tricks

Don’t you come across situations like you need to implement multiple header types for different categories? I’m sure you do. Here is a simple yet effective solution to work out the issue to implement multiple header types for different categories. For more conditional tags you can look up to .

First of all create the header files for each categories. Also have one header file as the default one. These files will be included from the main header.php file. Consider the code below for the your WordPress theme header.php file.

Advertisement



/**** Conditional Header for Per Category Example WordPress ****/

// make sure we are in category listing
if (is_category()){

Advertisement

if (is_category('1')){

}
elseif (is_category('2')){

}
else {
// this is the deafult header

}
}
?>

Example of using Category Names and Slugs

// Alternative for using Category ID, You can use Category Name or Slug
if (is_category()){

// example of using a category name
if (is_category('Category 1')){

}
// example of using category slug
elseif (is_category('category-1')){

}
else {
// this is the deafult header

}
}
?>

Alternatively you might want different headers for different pages, so I’ve included that example too.


//
// example of using header file based on pages
// note that you can either use page ID, Page Name or Page Slug
//

// this one uses page title
if (is_page('About')){

}
// this one uses page slug
elseif (is_page('subscribe')){

}
// this one uses page ID
elseif (is_page('6')){

}
else {

}
?>

Reminder: You need to use these codes inside your themes header.php file to load specific header elements based on condition.

  • LEO

    I would like do the same but with Custom Content Type that I created with Custom Content Type UI

  • Drewdclifton

    Hi thanks for writing this. I know it’s getting old but I have two questions that I can’t seem to answer for myself.

    1. Do I leave the word “TEMPLATEPATH.” as is, or is that meant to be where I put a path?

    2. How would I do this to have a custom header on the home page only (my home page is my posts page).

    Thanks!

  • http://www.facebook.com/people/Nursakti-Adhi-Pratomoatmojo/1008915926 Nursakti Adhi Pratomoatmojo

    Thank for this excelent post. But there are few bugs about the lines. Here the final tested of mine.

    In the header.php, replace all codes with this simple lines (below). please make the backup as newheader.php and don’t forget to prepare your modified header file e.g. category.php

    Hope it works for you guys.