Solving The WordPress Template Hierarchy Puzzle: Home vs Front Page

Josh Pollock - April 30, 2014

http://joshpress.net/blog/category/wordpress/tutorials/solving-the-wordpress-template-hierarchy-puzzle/http://joshpress.net/blog/category/wordpress/tutorials/solving-the-wordpress-template-hierarchy-puzzle/

The next post in my series on learning the WordPress template hierarchy is going to cover posts and pages. One of the things that makes this part of the discussion a little tricky is understanding the difference between home and front page templates.

WordPress themes can have two different template files “home.php” and “front-page.php” which seems confusing as front page and home page are two terms that are often used interchangeably. With WordPress, these two pages are different. Understanding the difference is a key step to understanding the WordPress template hierarchy for posts and pages as home and front-page templates complicate that part of the system.

The template hierarchy is the system for determining what file in a WordPress theme is used for displaying the current content. For more information about learning the template hierarchy, you should check out my post on learning the template hierarchy, which is full of great resources on the subject.

It is important to conceptually separate the list of most recent posts, which we call the blog index, from the home page. By default, WordPress shows the blog index on your site’s home page, using either “home.php” or if it doesn’t exist “index.php”.

No matter what your settings, if your theme has a “front-page.php” template then that template will be used to display the content when someone accesses the root level of your blog. This means that if your site is at example.com, when users go to example.com they will be served the content of “front-page.php”. If this template has a loop, it will either show a the blog index or a static page’s content. This is is determined by your site’s reading setting.

Of course, front-page.php does not have to have a loop in it. On this site, for example, I use a front-page.php with custom php to create the front page content. For most people, to create a static front page, it is probably easier to set WordPress to show a static front page and create your content using the WordPress post editor.

If you elect to show a static front page, this page will be generated using the “front-page.php” template. If one does not exist, WordPress will fallback through the template hierarchy for pages, which I will be covering in my next post. In this case, your blog index will be shown on whatever page you set in reading settings, and that output can be controlled using the “home.php” template.