WordPress Template Hierarchy

Template hierarchy in WordPress is essentially a series of rules WordPress follows to determine which template file to use to display content. Here’s a basic overview:

404 (not found)
1. 404.php
2. index.php

Search

  1. search.php
  2. index.php

Taxonomy

The default taxonomies in WordPress are:

  1. Categories: a hierarchical taxonomy that organizes content in the post Post Type
  2. Tags: a non-hierarchical taxonomy that organizes content in the post Post Type.
  3. Post formats: a method for creating formats for your posts.

Terms: Terms are items within your taxonomy. So, for example, if you have the Animal taxonomy you would have the terms, dogs, cats, and sheep. Terms can be created via the WordPress admin, or you can use the wp_insert_term() function.

taxonomy-{tax}-{term}.php
taxonomy-{tax}.php
taxonomy.php
archive.php
index.php


Home
home.php
index.php

If front-page.php exists, it will override the home.php template.


Attachment

  1. {MIME-type}.php can be any MIME type (For example: image.php, video.php, pdf.php).
  2. attachment.php
  3. single-attachment-{slug}.php – For example, if the attachment slug is holiday, WordPress would look for single-attachment-holiday.php.
  4. single-attachment.php
  5. single.php
  6. singular.php
  7. index.php


Single Post: The single post template file is used to render a single post. WordPress uses the following path:
single-{post-type}.php
single.php
index.php


Single Page
custom_template.php: The page template assigned to the page.
page-{slug}.php: If the page slug is recent-news, WordPress will look to use page-recent-news.php
page-{id}.php: If the page ID is 6, WordPress will look to use page-6.php.
page.php
index.php


Category

category-{slug}.php – If the category’s slug is news, WordPress will look for category-news.php.
category-{id}.php – If the category’s ID is 6, WordPress will look for category-6.php.
category.php
archive.php
index.php


Tag

tag-{slug}.php – If the tag’s slug is sometag, WordPress will look for tag-sometag.php.
tag-{id}.php – If the tag’s ID is 6, WordPress will look for tag-6.php.
tag.php
archive.php
index.php

Author
author-{nicename}.php – If the author’s nice name is matt, WordPress will look for author-matt.php.
author-{id}.php – If the author’s ID were 6, WordPress will look for author-6.php.
author.php
archive.php
index.php


Date
date.php
archive.php
index.php


Archive
archive.php
index.php