user2619611
user2619611

Reputation: 118

front-page.php overrides my custom page template wordpress

As the title says, I'm currently working on a theme and i've found a bit of a problem.

Let's say I make a page called test and give it the custom page template of test-page-template

so far that works fine if I go view the page but the problem comes when I set the homepage to use my page as the static homepage; what happens is instead of using the test-page-template it uses front-page.php.

The obvious work around would be to edit front-page.php to be the same as test-page-template but that's a bad solution if a client wanted to select a different page as the static front page. Any ideas?

Upvotes: 0

Views: 2637

Answers (2)

TamZam
TamZam

Reputation: 69

I found a solution for this question, although it is a question from a long time ago, maybe someone needs the same now

add_filter( "frontpage_template', 'selected_front_page_template" );

function selected_front_page_template( $template ) {

    $template_slug = get_page_template_slug();

    if( !empty($template_slug) ) {
        $template = locate_template( array( $template_slug ) );
    }

    return $template;
}

Upvotes: 0

Omar Tariq
Omar Tariq

Reputation: 7724

This is happening because of the WordPress template hierarchy. Front-page.php takes priority as compared to page template, when it comes to the front page of the blog. Here is the heirarchy graph:-

enter image description here

I'm not sure of the complete requirements, but I would suggest you to use index.php and page templates in that scenario.

Upvotes: 2

Related Questions