Understanding WordPress Template Hierarchy

Jan 21 2019

The Hierarchy Of WordPress Templates – All You Need To Know

WordPress is one of the leading platforms for site owners, thanks to its ease of use and designing. But the hierarchy of the template can be a bit complicated. Understanding the flow is of prime importance, especially to the beginners. For this reason, we have outlined the basic hierarchical flow of all the sections of a WordPress site.


Site Front Page

It is the front page of the website. The file of the front-page.php is the first thing that users will be looking at when the home page is loaded by WordPress. In case this file cannot be accessed, WordPress would turn to the home.php file. If this file is not available, the platform would then be falling back to using the trusty file of index.php. This file cannot be missing as the theme would never work in its absence.

 

In short, this WordPress template hierarchy breaks down into three other components:

  • Front-page.php file
  • The file for home.php
  • The default trusty file of index.php

 

WordPress would still be following the internal logic even if all these files are the same.


Single Posts

The articles posted on WordPress come under this category. The template files used to render a post are the internal elements of the page. For this reason, WordPress is required to fix on the template file that it would be using for the whole page before rendering the posts.

 

 

The WordPress hierarchy breakdown for single posts can be stated as follows:

  • Template file for single-{post-type}-{slug}.php
  • The file for single-{post-type}.php
  • Template for single.php
  • File for singular.php
  • Template for index.php

Single pages

It is an independent category for the WordPress platform and the single pages are referred to the other sections that constitute any website as a whole. While the home page is loaded under the template file for from-page.php, the web pages are categorized as single pages.

 

 

Below mentioned is the WordPress template hierarchy for single pages:

  • A template file that is customized as per the requirement
  • Page-{lug}.php template
  • Another file for page-{id}.php
  • Template for page.php
  • Template file for singular.php
  • File for index.php

 

WordPress has the capability to recognize multiple content types and deals them as single pages. This is the reason behind the first entry of this hierarchy to not be a filename.


Category and tag pages

The functioning of this hierarchy is more or less similar to the working of single pages and posts. The platform will first look out for the unique category template that you are trying to load. It will first tap into the filename that has its slug and progress on to the ID file. In case it fails, the platform will seek the category.php file followed by the archive.php.

 

The main templates in this section of the WordPress hierarchy include:

  • Category-{slug}.php file
  • A template for category-{id}.php
  • A file for category.php
  • Template for archive.php
  • File for index.php

Custom post types

Many users are unfamiliar to the types of custom posts. It is nothing but the contents that are not covered under the default category of WordPress classifications. To explain it simply, let us take an example where you are a blog owner and your posts are focused on reviews. This requires you to come up with a customized type of post named as reviews and requires you to customize the same if you want to incorporate the features you want.

 

There is a set template hierarchy WordPress flow for this section as well.

  • Archive-{post_type}.php
  • A preset template for archive.php
  • A file for the template of index.php

Search results pages

This section of WordPress is simpler in comparison to the above-mentioned parts. The search results are never known to be complicated, thanks to the simplicity of the linked layout. It is further supported by the prominent simplicity in the template hierarchy WordPress breakdown.

 

 

 

The hierarchy is as given below:

  • A basic template of search.php
  • The default trusty file of index.php

In case the customized template for the page of search results is not available, the platform will automatically turn to index.php by default. But some customized template is being brought in to the latest themes for search result pages as well.


404 error pages

Though none of the WordPress site owners expect that users not to face the error pages, it is one of the most integral components that demands your attention. This is because the platform does not come with a custom page for errors. But it is one of the easiest setup processes that hardly require you to invest any effort. You can create a customized error page of your own and WordPress would be depending on the below-mentioned hierarchy to look for it.

 

The hierarchy is stated below:

  • 404 php template file
  • The template file for index.php

This is the full hierarchical flow of WordPress templates. No matter what category may your WordPress site deal in, there can be no deviation from this default flow. While things appear to be complicated, it is actually much simpler. As you start working on your WordPress site, you will automatically realize the importance of all the components of the hierarchical flow.