Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm really confused with index.php, home.php and front-page.php. In many cases even though I had an index.php, I overwrite it with front-page.php. But recently, I became aware about home.php.

  • What's the difference between the home.php and index.php?
  • What's the ideal condition to use a home.php than an index.php?
  • What's the ideal condition to use a front-page.php?
  • When I'm using a front-page.php then what specific task an index.php is doing for me then?

I've read the Template Hierarchy in Codex. Please don't mix my question with Page Templates, I understand 'em, alHamduLILLAH.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

All this comes from a thorough reading of the Template Hierarchy.

home.php is used if:

  • Your site's front page is set to display a list of posts, or
    • A static front page is set, and
    • A visitor goes to the page that you've defined as your "list of posts" (eg, http://example.com/blog/)
  • And the theme has a home.php file

If the last condition isn't met -- ie, there is no home.php file in the theme -- then index.php will be loaded.

front-page.php will be used if:

  • A static front page is set, and
  • A visitor goes to the page that you've defined as your "static home page" (ie, http://example.com/), and
  • The theme has a front-page.php file

If the last condition isn't met -- ie, there is no front-page.php file in the theme -- then index.php will be loaded.

In summary

If you want to customize your list of posts, use home.php.
If you want to customize your static home page, use front-page.php.

share|improve this answer
1  
home.php will be used for the blog posts index, regardless of location. If the front page is set to display the blog posts index, then home.php will be used (if front-page.php does not exist). –  Chip Bennett Aug 16 '13 at 20:25
    
Ah, ok. Thanks for the clarification. –  Pat J Aug 16 '13 at 20:26

The front-page.php file is the site front page template. It will always be used on your site front page, regardless of whether get_option( 'show_on_front' ) is set to page or posts.

The home.php template file is the blog posts index template. It will always be used to display your blog posts index, regardless of whether the blog posts index is displayed on the site front page, or on a different page.

In the case that both front-page.php and home.hpp exist, and the get_option( 'show_on_front' ) is set to posts (i.e., the site front page displays the blog posts index), the front-page.php file will take precedence over the home.php file.

The index.php file is the default fallback template for all contexts in the Template Hierarchy. It is only ever used if a more-specific template file does not exist for the current context.

The template hierarchy for the site front page is:

  • front-page.php
  • If 'page' == get_option( 'show_on_front' ): page hierarchy
  • If 'posts' == get_option( 'show_on_front' ): blog posts index hierarchy

The template hierarchy for the blog posts index is:

  • home.php
  • index.php

The template hierarchy for pages is:

  • Custom page template
  • page-{slug}.php
  • page-{id}.php
  • page.php
  • index.php
share|improve this answer

In short:

  • index.php is a fallback template only, in case no appropriate template was found
  • home.php is used for the blog (a listing of recent posts)
  • front-page.php is used for the landing-page

The universal index.php template

The index.php template file is a fallback template. It is used as a last resort when no other more appropriate template is available. For example, if you don't have a front-page.php nor a home.php then index.php will be used. This is also true for missing archive.php or single.php and so on.

Regarding front-page.php VS home.php

Now the difference between front-page.php and home.php templates is that the front-page.php is used, as its name suggests, as the main front-page of the site, while home.php is intended to be the home of the Blog section.

What template will be used for my site's landing-page?

The front-page.php template, if present, will be used for the site's main front page (e.g. http://www.example.com/). If not present, then home.php will be used instead. If both the front-page.php and home.php template files are missing then the index.php fallback template will be used.

What template will be used for my blog page?

WordPress allows you to have a "Blog" page (which will list recent posts) on a different page than the landing-page (e.g. http://www.example.com/blog/). So if this is the case on your site, then the Blog page will always use the home.php template. If home.php doesn't exist then the index.php fallback template will be used.

How to configure the landing-page and blog page?

To configure what content to show on your front page, go to the WordPress Admin, under Tools > Reading, there you can configure the "Front page displays" to show a static page, or your latest posts.

In the case you choose to display a static page on the front page, then you also have the possibility to set which page to use as a placeholder for the Blog page (which will use the home.php template):

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.