Template Hierarchy: confused with index.php, front-page.php, home.php

Front page logic is one of the most confusing features in WordPress and is exceptionally hard to explain and summarize. As mentioned in comment while back I burnt unholy amount of time to put together my front page logic cheat sheet for it.

But since this is a popular thread let me try to answer those very specific questions you had.

What’s the difference between the home.php and index.php?

home.php is template for posts index (archive of native Post post type, which is a special case in WP). WP will attempt to look it up for index of posts, whether they are displayed at the root of the site or at dedicated posts page.

index.php is catch–all template. It is final choices in all branches of template hierarchy and will be picked when nothing else fits, for both archives and singular views.

Only posts index can use home.php, but all other contexts might and will use index.php.

What’s the ideal condition to use a home.php than an index.php

You use home.php to customize posts index.

You use index.php to provide the most generic template in your theme, suitable for display of anything.

Some themes choose to have empty index.php and ensure they have more specific templates for all possible cases, so it never has to be used.

What’s the ideal condition to use a front-page.php?

front-page.php is used for posts index at the root or static front page, if enabled.

It is a high priority template, so if theme has it you cannot select arbitrary template for static front page. For this reason it is almost never included in publicly released themes (which is correct).

The best use for it is in private projects, since it’s easier to configure than page template.

When I’m using a front-page.php then what specific task an index.php is doing for me then?

index.php is still a catch all template for all other cases.

If you use static front page (to which front-page.php will apply) then your posts page will try to use home.php and then index.php.

Leave a Comment