Foundations in WordPress: How to setup a second WordPress header

Written by:
Logan Holdaway

Setting up a second header is easy to do in WordPress.
Find your header.php file in your theme directory and duplicate the file. Change the file name to header-customheader.php. Now you can call custom header within whichever template you want using the following function.

<?php get_header('customheader'); ?>
Most template files are set up like this so that the function to call the header also tells WordPress which template this is:


<?php
/*
Template Name: Front
*/
get_header(); ?>
			

Don’t worry about deleting the function that already exists and writing it below. Just add the perameter like so:


<?php
/*
Template Name: Front
*/
get_header('customheader'); ?>
			

The benefit creating a second header like this is that it gives you two navigation bars to work with so you can style them separately. Using this method also makes it easy to include a hero image above the navigation.
If you’re a developer building a site for someone else, you’ll be glad to know that it is possible to included custom fields within the header file using Advanced Custom Fields. For those who don’t know, the benefit of custom fields is that it allows the user to change content in the backend of WordPress without having to dabble with code.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>