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




}
elseif (is_category('2')){

}
else {
// this is the deafult header

}
}
?>

Example of using Category Names and Slugs


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

}
else {
// this is the deafult header

}
}
?>

Advertisement

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



}
// 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.