Saturday, March 7, 2015

How to Implement Separate Headers for Pages in WordPress?

How to Create Headers for Separate Pages in WordPress

To create separate headers, first of all create a new PHP file, and name it appropriately. Here I’ll name my file header-your-page.php and put the complete code on the same.
To call a particular header, you will need to page template file call page.php and replace your normal header code with below code:
1
2
3
4
5
6
7
8
9
10
11
<!--?php 
/* 
*/
if(is_page(23)) {
 get_header('about');
}
else {
 get_header();
}
 wp_head();
?-->
As you can see above, we have used get_header functionality. We have created a new custom file with the name header-your-page.php and have used if(is_page(23)) as an ID of the page for which we want to create a separate header. Further, get_header(‘about’) is the same alias which was used while creating “header-your page name.php” example header-about.php.

In simple words, the code above is basically informing WordPress that if someone opens the page, which is ‘about’ then WordPress will display a file called header.about.php if it is existing. If the file does not exist, then WordPress will render the default header file.

Editing Existing WordPress Headers

You can not only create headers for different WordPress pages but also edit them to add an extra dimension to them. It’s an extremely simple process. All you need simply open the file in any of the graphic program such as photoshop. You’ll need to save the image again and edit the name of the file. Then reload it.
To locate the name of the file, just click right on the header image and select the option “view image”. Once you click on the option, you’ll be provided with the path to the image along with its stored location on the web server. This is crucial for a successful implementation of the header image editing task.

To Sum Up

As you can see, with the help of a simple code, you can easily implement separate headers for different WordPress pages. I hope this tutorial help you with how to get a separate header for each page. You can also make adjustments to their styles (the process is already mentioned above), so keep chipping away until you get just right.

0 comments:

Post a Comment