WordPress: Create and use a second header.php file

Good afternoon friends! Today I want to share a very easy way to incorporate a second header.php file into your WordPress theme.

First, let’s create the second header.php file. Typically, I will just copy and paste the codes of the original header.php file, edit them as I see fit, and then save the new file as my second header.php file.

For this example, I will use just a very simple header. Paste this code into a text editor:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title><?php if ( is_home() ) { ?><? bloginfo('name'); ?>&nbsp;<?php bloginfo('description'); } else { wp_title('&nbsp;'); ?>&nbsp;by&nbsp;<? bloginfo('name'); } ?></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="shorcut icon" type="image/x-ico" href="<?php bloginfo('template_url'); ?>/favicon.ico" />
<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/javascript/imghover.js"> </script>
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
<?php wp_head(); ?>
<!-- header START -->
<div class="Header">
<h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1>
<div class="Desc"><?php bloginfo('description'); ?></div>
<!-- header END --><!-- container START --><div class="Container">

Now, save  the file as header-secondheader.php (or whatever you want the second header to be called). Just make sure it is in the format of header-yournewheader.php.

Upload the file to the correct folder on your server – ” …/wp-content/themes/yourthemename“.

Next, open the template page that you want to use the second header for. For this example, let’s say it is index.php.¬† Find this line of code:

<?php get_header(); ?>

And replace it with this:

<?php get_header('secondheader'); ?>

Of course, make sure that the name in the parentheses is the name of your second header.

That should work for you, but as always, let me know if you run into any issues at all.