Beginners Guide to WordPress Template Hierarchy

Every WordPress based website uses a component called theme which powers its entire front-end design, styling, color and the overall content presentation. The theme is something like a dress. It’s a crucial part of a WP site. WordPress themes have some distinct parts named templates. An individual Theme is broadly a combination of several templates including other stuff. Templates are used to shape different parts of a WP site.

For example, a single article page essentially looks different than a category archive page. Again an article post (e.g. single blog post) will have some distinguishable features when compared to a Page post (e.g. About Us). Respective templates define these characteristics.

Now that, there are more than a few templates in a theme. The WordPress content management system (CMS) calls the suitable template each time a user visits the site or its internal pages. So, which template is to be called and render the requested page with? Yes, that’s a good question, and this is when template hierarchy comes into the game.

WordPress template hierarchy determines which template file should be used to display a certain type of page/content(s). An individual web page can suite to more than one templates. For example, the Category archive and Author archive both show a number of posts, generally as a list. These are archive pages. When a visitor hits a specific author’s post archive, WordPress can simply use the archive.php template to render the page. But WordPress allows the developers to offer more customized and personalized the user experience.

That’s why there is an opportunity to utilize individual archive template for a certain archive. Each archive can be defined to use a specific template. So WP will try to render the respective page using that defined template file. If, for some reasons, the CMS doesn’t get a specific template for a request, it will render the page using the next best alternative. This total procedure follows an order or chain. This is called the hierarchy. It begins with the most specific template type (e.g. author archive, single post page) and ends with a common template (index.php).

Get 20% off on the Best WordPress Themes & Plugins

Get 20% off on the Best WordPress Themes & Plugins

A WordPress theme generally has the following templates:

  • index_template
  • 404_template
  • archive_template
  • author_template
  • category_template
  • tag_template
  • taxonomy_template
  • date_template
  • home_template
  • front_page_template
  • page_template
  • paged_template
  • search_template
  • single_template
  • text_template, plain_template, text_plain_template (all mime types)
  • attachment_template
  • comments_popup

 

Now let’s see the template hierarchy!

Before we bring here is a visual overview:

WordPress Template Hierarchy Visualization

Click here to see the interactive version.

Homepage

Site front page (if the front page displays posts)

  • front-page.php
  • home.php
  • index.php

 

If the front page displays a page (static home page), the hierarchy will go like this

  • front-page.php
  • page-$slug.php
  • page-$id.php
  • page.php
  • index.php

 

Single Post (Post Type- ‘Post’)

Template hierarchy for a single blog post

  • single-post.php
  • single.php
  • singular.php (v 4.3+)
  • index.php

 

Template hierarchy for a custom single blog post

  • single-$posttype-$postname.php (v 4.4+)
  • single-$posttype.php
  • single.php
  • singular.php (v 4.3+)
  • index.php

 

Template hierarchy for an attachment post

  • $mimetype.php
  • $subtype.php
  • $mimetype_$subtype.php
  • attachment.php
  • single.php
  • singular.php (v 4.3+)
  • index.php

 

Single Page (Post Type- ‘Page’)

Template hierarchy for a default single Page post

  • Page template
  • page-$slug.php
  • page-$id.php
  • page.php
  • singular.php (v 4.3+)
  • index.php

Note: Custom page templates can also be used. WordPress will prioritize that template for the specific page.

 

Archive Pages

Archive pages are rendered by following a well-organized hierarchy or order. The CMS also checks if the output archives are paged or not.

 

Archive pages hierarchy (general)

  • archive.php
  • index.php

 

Author Archives

Hierarchy for an archive page that will display the entries by an individual author

  • author-$nicename.php
  • author-$id.php
  • author.php
  • archive.php
  • index.php

 

Category Archives

Hierarchy for an archive page which will display the entries by an individual post category

  • category-$slug.php
  • category-$id.php
  • category.php
  • archive.php
  • index.php

 

Custom post type archive template hierarchy

  • archive-$posttype.php
  • archive.php
  • index.php

 

Custom taxonomy archive template hierarchy

  • taxonomy-$tax-$term.php
  • taxonomy-$taxonomy.php
  • taxonomy.php
  • archive.php
  • index.php

 

Date archives template hierarchy

  • date.php
  • archive.php
  • index.php

 

Tag archives template hierarchy

  • tag-$slug.php
  • tag-$id.php
  • tag.php
  • archive.php
  • index.php

 

Blog post index page template hierarchy

  • home.php
  • index.php

 

Comments popup page template hierarchy

  • comments-popup.php
  • index.php

 

Error 404 page template hierarchy

  • 404.php
  • index.php

 

Search result page template hierarchy

  • search.php
  • index.php

 

Here you can see the detailed hierarchy/order of WordPress templates. These PHP files are located in a WP theme. If you dig inside of a WordPress theme, you can find the templates there. For a visual presentation, you may see this page as well.

Tags:
,
Editorial Staff
mail@85ideas.com

Editorial Staff at 85ideas is a team of WordPress experts led by Brian Harris. Here to share amazing tuts, guides and collections.

No Comments

Post A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.