I've noticed there are a lot of similar posts, but can't seem to sift through the pile for the right one.
I'm creating a custom theme. I have a separate file, "foo.php", that I want to be the un-editable homepage or front page of the the site.
Then, I want to use a different file/template for the rest of the site.
How do I do this?
At the very top of the foo.php
template, insert the following code:
<?php
/*
Template Name: Home Page Template
*/
?>
In WordPress, create a page called "Home" (or really, whatever you like). You don't need to add any content using the editor if it's all in the foo.php
file. To the right of the editor you'll see a dropdown that lets you choose a template - pick the one you just created, "Home Page Template".
Last, go to the "Reading" section of the WordPress dashboard and set your newly created page, "Home" as a static front page.
All you have to do is create a new file and name it home.php
, and you can use any WordPress parameters in there. This file will automatically take over your index.php
, and it will be displayed as your homepage.
From the documentation:
WordPress first determines whether it has a static front page. If a static front page has been set, then WordPress loads that page according to the page template hierarchy.
If a static front page has not been set, then WordPress looks for a template file called home.php and uses it to generate the requested page.
If home.php
is missing, WordPress looks for a file called index.php
in the active theme's directory, and uses that template to generate the page.
You can either create a static front page by going to Reading settings in your dashboard, or using the first method.
Hope this helps!