Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Don Noray
Don Noray
19,238 Points

Coding the Header and Footer Templates

I'm currently working on a project while learning WordPress Theme,but my site has a slight difference in the Home page header that the rest of the site. I used get_header() to retrieve the header file. If I create a different header for the Front-page file how do I retrieve that header file and allow the rest of the site to retrieve the default one?

6 Answers

John Wheal
John Wheal
27,969 Points

Name the header file header-home.php and retrieve it with

<?php
if ( is_home() ) :
get_header('home');
else :
get_header();
endif;
?>
Don Noray
Don Noray
19,238 Points

Thanks John, but its now showing up. I believe that I probably did something wrong. I placed the conditional at the top of the front-page.php file: <?php if ( is_home() ) : get_header('home'); else : get_header(); endif; ?> Is that the correct place to put it?

Colin Marshall
Colin Marshall
32,861 Points

Are you 100% sure what you're looking at is the front-page.php template? If you're not sure, just put some paragraph text in the front-page.php file that says "This is the front page" to verify you're looking at the right template.

Don Noray
Don Noray
19,238 Points

Colin, I did add the "This is the front page" to the front-page file but the code did not work. I used <?php get_header('home'); ?> and it worked. Will this caused any problems that I'm unaware of?

Colin Marshall
Colin Marshall
32,861 Points

If it works how you want it to I wouldn't think there is a problem. I think the if statement mentioned by John Wheal is something that is intended to be used on every template page to get the header, but it's not necessary to accomplish what you're trying to do. Maybe it's better practice to do it that other way? I'm not sure.

Don Noray
Don Noray
19,238 Points

Thanks again Colin