Quick answer: The WordPress template hierarchy is the set of rules WordPress uses to decide which theme file displays each page. When someone visits a URL, WordPress works out what kind of page it is, such as a single post, a page or a category archive, then looks through a list of possible template files from most specific to most general. It uses the first one it finds. If nothing more specific exists, it falls back to index.php, which every theme must have.
You do not need to be a developer to benefit from understanding this. It explains why some pages on your site look different from others, why a change to one template affects many pages, and what your developer means when they talk about “creating a custom template”.
Why the template hierarchy matters to you
Knowing the basics helps you:
- Understand quotes for theme changes, since each new template is a piece of work
- Brief developers clearly, for example “the services category should look different from the blog”
- Avoid losing changes when a theme updates, by using a child theme
- Diagnose why a page does not look the way you expect
How WordPress picks a template
Every time a page loads, WordPress follows three steps:
- It works out the type of request. Is this the front page, a single post, a page, a category, a tag, an author archive, a search result or a missing page?
- It builds a list of possible templates for that type, from most specific to most general.
- It checks the active theme for each file in order and uses the first one that exists.
If you use a child theme, WordPress checks the child theme first, then the parent theme, for each file.
The main templates in plain English
The front page
WordPress checks for front-page.php first. If your Reading settings show a static page as your home page, it can also use that page’s own template. If your home page shows your latest posts, it falls back to home.php, then index.php.
This is why changing your Reading settings can change how your home page looks.
The blog posts page
The page listing your latest posts uses home.php if it exists, otherwise index.php. Many people find this confusing, because “home” here means the blog index, not necessarily your site’s front page.
Single blog posts
For an individual post, WordPress looks for:
- single-post.php
- single.php
- singular.php, newly added in WordPress 4.3 as a shared fallback for both posts and pages
- index.php
For custom post types, such as “projects” or “testimonials”, it checks for a file named after the post type first, such as single-project.php.
Pages
For a page, WordPress looks for:
- A custom page template chosen in the page editor, if one is selected
- page-{slug}.php, for example page-contact.php
- page-{id}.php, for example page-42.php
- page.php
- singular.php
- index.php
Custom page templates are the most flexible option for site owners. Your developer creates a file with a special comment at the top, and it then appears as a choice in the “Page Attributes” box when you edit any page. That lets you apply a landing page layout, or a full width layout, to any page you choose.
Category archives
For a category, WordPress looks for:
- category-{slug}.php, such as category-news.php
- category-{id}.php
- category.php
- archive.php
- index.php
This is how a developer can make one category look different from the rest, for example a “Case Studies” category with large images while normal blog categories show a simple list.
Tags, authors and dates
These follow the same idea. Tags use tag-{slug}.php, then tag.php, then archive.php. Author archives use author-{nicename}.php, then author.php, then archive.php. Date archives use date.php, then archive.php.
Search results
Search results use search.php, then index.php. A well designed search template makes a real difference on content heavy sites.
The 404 page
When a page cannot be found, WordPress uses 404.php, then index.php. A helpful 404 page with a search box and links to popular content keeps visitors from leaving.
Template parts and why they matter
Most themes break templates into reusable pieces, such as header.php, footer.php and sidebar.php, plus smaller parts loaded with the get_template_part function. A change to header.php updates the header across the whole site. That is efficient, but it also means a small change can have a wide effect, so changes should be tested properly.
Child themes: protecting your changes
If you or your developer edit the files of a theme you bought or downloaded, those edits will be overwritten the next time the theme updates. A child theme solves this. It is a small theme that inherits everything from the parent, and any template file you place in it overrides the parent’s version. This is the standard way to customise a ready-made theme safely.
Practical examples
- A different layout for your services pages: create a custom page template and select it on each service page.
- A unique contact page: a page-contact.php template applies automatically to the page with the slug “contact”.
- Case studies as their own section: register a custom post type with an archive and single template of its own.
- A better blog listing: improve home.php or archive.php so every archive benefits.
How to see which template a page uses
Plugins such as “What The File” or “Show Current Template” display the template file in the admin bar while you browse your site. This is very useful when briefing a developer.
Questions to ask your developer
Understanding the hierarchy makes conversations with developers much easier. Useful questions include:
- Which template files will this change touch, and which other pages use them?
- Are you working in a child theme so updates are safe?
- Will this be a custom page template I can apply myself, or a template tied to one page?
- How will this template behave on phones and tablets?
- What happens to these pages if we change themes later?
Good answers show the developer has thought about how the change fits the whole site, not just the page in front of them. Vague answers are a sign to ask more.
A note on page builders
If your site uses a page builder plugin, many layouts are stored in the page content rather than in template files. The template hierarchy still decides the outer frame, such as the header, footer and sidebar, but the builder controls what sits in the middle. That is worth knowing before you plan a theme change, because builder layouts may not carry over cleanly.
FAQ
Can I change templates without coding?
You can choose between custom page templates your theme provides in the page editor. Creating new templates needs a developer or a page builder.
What happens if a template file is missing?
WordPress simply moves down the list until it finds one. Since index.php is always there, a page will always display.
Does the template hierarchy affect SEO?
Indirectly. Templates control headings, structured markup, speed and internal links, all of which affect how search engines read your pages.
Need theme work done properly?
We build and customise WordPress themes that are easy to manage and safe to update. See how we turn visitors into customers.