Swap Homepage Header

Put a different header on the homepage

So, we've decided we want to put a tagline ("Yay, beer!") under the site title, but only on the homepage. The header is normally included using the get_header() call in the template file. Prior to Carrington Core f you wanted to have a different header on the homepage, you had two choices:

  • Create a separate homepage-header.php file, remove the get_header() and replace it with an include('homepage-header.php')
  • Put some conditional code into your header.php file that re-structured the markup for the homepage

Neither of these options are ideal. In the first, you've lost the benefits of the get_header() call (vs. an include). In the second, you have conditional code in there that's going to require maintenance.

Instead of conditional code, Carrington Core uses the file name to include a specific header when certain conditions are met. So, we can create a second header called home.php in the /header/ directory inside of our theme.

Lets get our tagline implemented for the homepage. Inside the /header/ folder you'll find a file called header-default.php. This is the file Carrington Core includes if it can't find anything else that matches. Since it's all we have in there, that's what's being included as the header.

Make a copy of that file and rename it 'home.php'. Changing the name to home.php tells Carrington Core that it should use this header when it's building the homepage. Open that file up and lets implement the tagline right under the <h1>. Make it an <h2>:

	
20  |    <h1>Our Beer Site Name</h1>	
21  |  <h2>Yay, beer!</h2>	
22  |</div>

Save the file and reload your homepage (you should see the tagline). Now look at another page on the site and notice the tagline isn't there. Pretty slick, huh?

Moving right along...