Key Takeaways
- The WordPress template hierarchy defines the order in which theme files are loaded.
- Understanding the WordPress hierarchy helps developers save time and customize themes effectively.
- Core files like index.php, single.php, and archive.php are key parts of the WordPress theme hierarchy.
- Using child themes ensures safe customization without breaking parent theme updates.
Creating a WordPress theme starts with understanding the WordPress template hierarchy. The template hierarchy is the system WordPress uses to decide which file in your WordPress theme hierarchy should load when displaying a page, post, or archive.
By learning how the WordPress hierarchy works, developers can build themes faster, customize layouts with precision, and reduce trial-and-error during development.
This guide covers the structure of the WordPress template hierarchy, key template files, and practical tips to speed up your theme development process.
- What Is the WordPress Template Hierarchy?
- Structure of the WordPress Hierarchy Explained
- WordPress Theme Hierarchy by Page Type
- Essential Template Files in the WordPress Hierarchy
- How the Template Hierarchy Works in WordPress
- Why Template Hierarchy Matters for WordPress Development
- How to Locate and Edit the WP Template Hierarchy
- Child Themes and the WordPress Theme Hierarchy
Master WordPress Template Hierarchy with Cloudways
Learn WordPress Template Hierarchy and try Cloudways managed hosting for a hassle-free theme development experience.
What Is the WordPress Template Hierarchy?
Since WordPress is a dynamic site, each component has a template, which can vary depending on the theme.
Whenever a query is generated, WordPress loads a page corresponding to that query. This query travels through the template hierarchy to give the desired output.
So, the template hierarchy is a system used by WordPress to determine the order of template files required to display the selected webpage on your website.
Structure of the WordPress Hierarchy Explained
The following diagram shows which template files are called to generate a WordPress page based on the template hierarchy.

Source: WordPress.ORG
WordPress Theme Hierarchy by Page Type
Most WordPress websites use seven types of pages, as follows:
- Front page template files
- Single posts
- Single pages
- Custom post types
- Search result pages
- Category and tag pages
- 404 error pages
In this section, we will discuss the template hierarchy of each page.
Front Page
Your front page is the first landing spot for users. Although the front page layouts vary from site to site, they follow the basic theme. This implies whenever a query string related to the front page is generated, the following files load in order:
- Front-page.php
- Home.php
- Index.php

If your theme doesn’t have front-page.php, WordPress will load the second in the order and so forth. When there is no template file, WordPress returns index.php, which is the final stop for every query in the template hierarchy.
Single Posts
The individual articles are considered single posts and use a single post template hierarchy.
The template hierarchy for single posts can be complex depending on your customization options. However, the basic template hierarchy for single posts is as follows:
- Single.php
- Singular.php
- Index.php

Single Pages
Similar to single posts, single-page templates can have a complex template hierarchy. The basic template hierarchy of single pages is as follows:
- Page.php
- Singular.php
- Index.php

Custom Post Types
WordPress lets you create custom post types for your website to give a unique touch to your brand. Custom post types help keep your customers glued to the site and have their own template hierarchy, described in the following order:
- archive-{post_type}.php
- archive.php
- Index.php

Although the template hierarchy for custom post types is simple, you can add more elements to it depending upon your own customization levels. Moreover, you can also create a custom page template in WordPress themes.
Search Result Pages
Almost every WordPress site comes with a search feature. The search results page follows a simple template hierarchy, depicted as below:
- Search.php
- Index.php

Category and Tag Pages
WordPress generates collective pages for tags and categories. Category and tag pages can involve many elements, with their own template hierarchy. This is why the template hierarchy of category and tag pages can be versatile and complex.
Here’s how the basic templates of the category page look:
- category–{slug}.php
- category-{id}.php
- category.php
- archive.php
- index.php

Whereas the basic templates of the tag page look as follows:
- tag–{slug}.php
- tag-{id}.php
- tag.php
- archive.php
- Index.php

404 Error Pages
Whenever users try to access a page that doesn’t exist, WordPress returns a 404 error page. Although there isn’t much you can change on the page; you can still customize the template per your needs.
The 404 error page template hierarchy is fairly simple and looks as follows:
- 404.php
- Index.php

Essential Template Files in the WordPress Hierarchy
You can include some WordPress files in almost all page templates, and they are as follows:
- Index.php
- Header.php
- Footer.php
- Sidebar.php

Index.php
Index.php is that template file in the WordPress page hierarchy, which is necessary for a WordPress theme to function. It is most commonly used to render a theme’s home page. Understanding this file will help you pick up the best WordPress themes you may use for your site.
The index.php file usually contains other template files like header.php, footer.php, and sidebar.php, which include the site’s head section, footer area, and sidebars with widget areas, respectively. It also includes a loop that displays the posts or pages on the template.
Whenever a template file doesn’t exist, e.g., single.php or post.php, WordPress loads the index.php.
Header.php
The header.php file contains a WordPress site’s head section and is commonly called at the start of all the template files. It usually contains header information, analytics, calls to CSS files, site navigation, page titles, site logo, etc.
Footer.php
The footer.php file is used to build the footer section of a WordPress theme. It is called in the footer section of all the template files. The file generally contains copyright information, calls to JS files, and widget areas with site navigation.
Sidebar.php
The sidebar.php file, as the name suggests, is used to build the sidebar of a site and generally contains widget areas for easy customization. To call the sidebar, it is called in template files like index.php, page.php, and single.php. You can also remove the sidebar from the site if your design requires it.
Some other template files that we generally use but aren’t mandatory are as follows:
Search.php
Search results in WordPress use the template file search.php. If the file doesn’t exist, search results are rendered from index.php.
Attachment.php
Th attachment.php template file renders attachment pages, such as images and videos. The image.php and video.php files are used to render photos and videos, respectively. And if these files don’t exist or aren’t found, then the system uses attachment.php.
404.php
The 404.php file gives the not found page; if the file doesn’t exist, the error page is rendered from the index.php file.
Comments.php
The comments.php file is a template of comments and is called in template files like single.php or page.php to add the comments section.
How the Template Hierarchy Works in WordPress
WordPress uses a query string to decide which template or set of templates to use for displaying the page.
In simple words, WordPress searches through the template hierarchy until it finds a matching template file. Here’s how it works:
- Firstly, WordPress takes the user input or query string.
- It checks the theme that the particular site currently uses.
- Then, it matches the query string with the query type to determine which page is requested and fetches the relevant template hierarchy.
- Check for the availability of the first template file.
- If it’s available, then display; otherwise, show the next file in order.
- If nothing is available, display the index.php file.

Why Template Hierarchy Matters for WordPress Development
We need a template hierarchy to customize our WordPress sites easily. Moreover, you may need a template hierarchy for the following purposes:
- Tell WordPress which template files within a theme to use at any time.
- It gives you an edge to customize your themes as per your needs
- It enhances user understanding of the theme
- It keeps the WordPress system organized
How to Locate and Edit the WP Template Hierarchy
You can easily locate the WordPress template hierarchy by accessing the application’s root folder using a Filezilla FTP Client. Follow the steps below:
- Use the Master Credentials to connect to the FTP client.

- Go to Applications and select your WordPress application by the database name.

- Navigate to public-html.

- Select wp-content.

- Click themes

- Select your theme. Here I’m selecting twentytwentyone.

- You will see a list of all your .php files.

- Open any of the .php files to edit as per your preferences.

Child Themes and the WordPress Theme Hierarchy
You can also use child themes in the WordPress template hierarchy, despite them not being much evident in the cheat sheet.
Using a child theme is your best bet if you wish to customize the WordPress theme. It lets you safely edit your themes and adds a second layer to the template hierarchy for any page type you use.
Other than that, you can also use full site editing themes to customize your web pages.
Final Words
Understanding the WordPress template hierarchy is beneficial if you want to develop custom themes and customize the WordPress theme file structure. It will let you easily find the right template files to edit and customize. Once you have set up your WordPress hosting, and have your servers up, you can now understand how template hierarchy works for that.
The best thing about the WordPress template hierarchy is that it follows a strict naming convention. So, you can easily create WordPress themes once you get a hold of the template hierarchy. You may refer to the WordPress theme hierarchy for a quick visual reference for theme development
Frequently Asked Questions
1. What is the WordPress template hierarchy?
The WordPress template hierarchy is the system WordPress uses to decide which theme file to load when displaying a page, post, archive, or category. It ensures your site displays the correct layout automatically.
2. How do you create a hierarchy in WordPress pages?
WordPress lets you create a page hierarchy by setting parent-child relationships between pages.
- Go to Dashboard → Pages → Add New (or edit an existing page).
- In the Page Attributes panel, choose a Parent page from the dropdown.
- Save or publish the page.
Example: A “Services” page can have “Web Design” and “SEO” as child pages.
3. What is the hierarchy of WordPress user roles?
The WordPress hierarchy of user roles determines permissions on your site:
- Administrator → Full access to all settings, content, and users.
- Editor → Can publish/manage all posts and pages.
- Author → Can publish/manage only their own posts.
- Contributor → Can write/edit posts but cannot publish.
- Subscriber → Can only manage their profile and read content.
4. Why does the WordPress template hierarchy exist?
The WordPress hierarchy provides a structured way to load theme files. It simplifies development by giving WordPress developers predictable control over which WordPress theme hierarchy file is used for each type of content.
5. What are WordPress template files?
WordPress template files are theme files that control how your site’s pages look and function. Common examples include:
- header.php → site header
- footer.php → site footer
- single.php → single posts
- archive.php → category or archive pages
- index.php → fallback file in the theme hierarchy
Sarim Javaid
Sarim Javaid is a Sr. Content Marketing Manager at Cloudways, where his role involves shaping compelling narratives and strategic content. Skilled at crafting cohesive stories from a flurry of ideas, Sarim's writing is driven by curiosity and a deep fascination with Google's evolving algorithms. Beyond the professional sphere, he's a music and art admirer and an overly-excited person.