Load a Different Header in WordPress

This little snippet can come in handy when you need to serve a different header on a per page basis.

All you need to do is create a new header file – header-yourfilename.php and then put in some logic in your desired template file.

In my case I have a header file called header-home.php and in my homepage template I include the following at the top like so:


if(is_front_page())
{
    get_header('home');
}
else
{
    get_header();
}
?>

It is probably worth mentioning that if you want your header on a different type of page, all you need to do is adjust the conditional tag. More information on conditional tag’s can be found on the codex.

Jake Bresnehan

A Front End Developer based in Sydney and the creator of Web Design Weekly.

Web Design Weekly keeps developers at the forefront of techniques and trends whilst helping them learn and grow to produce top quality code to make the web a better place for all.

1 Comment

  1. Thanks! That’s exactly what I needed to know.

This post currently has one response. What do you think?

You can use basic HTML when posting code, please turn all < characters into &lt; or > into &gt;
If the code is multi-line, use <pre><code></code></pre>

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *