web hosting
build a website

Set specific page headers in WordPress

Apr 5, 2013   //   by Anthony Devine   //   Website Development tips  //  Comments Off on Set specific page headers in WordPress

In the WordPress standard theme it is not always relatively straight forward to create a different page header for each page. So if you want a default header for the Website and then on a few pages this to alter you can do this using PHP in your theme.

What you need to do in the backend of your site in Apperance > Editor, copy the code out of your header.php file and then paste this code into a new file called headerdefault.php. Once you have done that then replace the code in your header.php file with the following code:

<?php
if (is_page('contact')){
include(TEMPLATEPATH.'/headercontact.php');}
elseif (is_page('portfolio')){
include(TEMPLATEPATH.'/headerportfolio.php');}
elseif (is_page('about-me')){
include(TEMPLATEPATH.'/headerabout.php');}
else {
include(TEMPLATEPATH.'/headerdefault.php');}
?> 
This code basically says if the page title is contact then use the header headercontact.php, or if the title is portfolio then use the header headerportfolio.php, or if the title is about-me then use the header headerabout.php and if the page title is something different to those titles then use the default header headerdefault.php which you have just created. So now you need to create the headers; headercontact.php, headerportfolio.php and headerabout.php use the code from the headerdefault.php in each of these and change the code accordingly to be whatever you want for each of the pages.

This can also be done for the sidebars and footers, you just need to use the same proceedure as above. This was the easiest and fastest way I found to code this up, this are probably plugins that can do this for you now but if you do not want all the additional bulk installed onto your site then use this method.