1
votes

I have created a template in wordpress for the home page, named: page-home-slider.php I have chosen the home page to take that custom template. Until here everything works fine.

Then I have created header-home.php, so a custom header for my home page. Then in page-home-slider.php I have coded: get_header("home");

Now, when I access the home page from browser, the default header is displayed first and under it, my custom header. Is this normal? I wanted to have just my custom header. Please tell me what I am doing wrong.

PS: I am using JobRoller template if it matters somehow.

sample picture

1
Is there a reason for not simply replacing the code in the header.php file with your header code instead of making a custom header file. That way you can simply call get_header(). What it looks like to me is that since the original header.php presumably still exists, it must be getting called somewhere. Without seeing your code there isn't a lot we can do though. - Ryan Fitzgerald
Can you please post the code of page-home-slider.php? It seems that get_header() is being called twice, the default first then your custom one. Please run a search in your theme directory to check where it's being called. - Aziz
@RyanFitzgerald The reason is because I want to have a different header for my home page and a default one for the rest of the pages (yes, header.php exists). Is there a method to do this in header.php only? - Catalin
@Aziz I cannot paste the code as it is too long, but I searched get_header() on it and it doesn't appear anywhere. - Catalin
@Catalin you can use an if statement in header.php that checks if the page matches your template: if (is_page_template( 'page-home-slider.php' ) ) { ... } see docs: developer.wordpress.org/reference/functions/is_page_template - Aziz

1 Answers

1
votes

As discussed in the comments, you could set a condition in header.php that checks if the requested page has the template using the is_page_template() function:

header.php

if ( is_page_template( 'page-home-slider.php' ) )
{
   // do something different
}  

Still, you need to check where get_header() is getting called to avoid duplicates.

Reference: https://developer.wordpress.org/reference/functions/is_page_template/