Front-page-only header.php

Hello,

I’m new here! How do I define a header.php file specific only to the homepage? I tried renaming header.php to front-header.php but it would not get displayed .

I’m reading about Extending Templates.

Thank you.

You need to call the template:

in:
base-front-page.php

For example I called the template “home-header”

get_template_part('templates/home-header');

Hello,

I created a file base-front-page.php with empty content just to test if it works. I refreshed the page and i’m still getting contents.

Thank you.

Where did you put it? An empty base-front-page.php should definitely show no content on your home.
Base templates need to be in theme root. Just checking you didn’t put it in your templates folder.

Hello,

I put it in the base of the theme folder.

pussy cat

Thank you.

For now,

I edited base.php with:

get_template_part(is_home() ? 'templates/header-home' : 'templates/header');

That works. I don’t know why it’s not reading your base-front-page template. Sorry.

You would need a front-page.php file to exist before base-front-page.php would work.

I would just go with adding a conditional to the normal header template in templates/header.php

<?php if (is_front_page()) : ?>
  <header>
    Front page header
  </header>
<?php else: ?>
  <header>
    Default header
  </header>
<?php endif; ?>
1 Like

You need to copy:
copy base.php to base-front-page.php
then create a empty front-page.php
a front-header.php in /templates
In base-front-page.php change get_template_part(‘templates/home-header’); to get_template_part(‘templates/front-header’);

With <?php if (is_front_page()) : ?> is too messy, but it works too for a small website.

Oh, that’s it! I just needed a front-page.php file. Thanks!

This topic was automatically closed after 3 hours. New replies are no longer allowed.