WordPress template hierarchy

WordPress decides which files to use for a page based on a hierarchy of templates that gradually decrease in specificity.

🛈 More information about the WordPress template hierarchy can be found on the official WordPress documentation site.

The bottom level, which WordPress will default to if no other template is available, is the index.php file. The inclusion of this file is essential for any WordPress theme to be valid.

The following template files are also considered essential in any WordPress theme:

  • archive.php – displays a list of all posts.
  • single.php – displays a single post.
  • page.php – displays a static page.
  • home.php – displays a bespoke list of posts for either the Homepage or Posts page (defined in the Reading Settings of the Admin Dashboard)
  • 404.php – displays an error page if a requested post isn’t found
  • search.php – displays a list of posts based on a search query.

You should create the above files in the root folder of your theme.

Additional, optional template files that may be appropriate to use, include:

  • front-page.php – displays a custom static page on the Homepage (overrides any page set in Reading Settings).
  • singular.php – a replacement for both single.php and page.php if separate template files are not required.

Leave a Comment