The WordPress Template Hierarchy, Explained Simply

The WordPress Template Hierarchy, Explained Simply

Every time somebody opens a page, WordPress asks itself what kind of page it is and looks for the most specific template the theme has for it. If it doesn't find one, it tries a more general one, and so on until it reaches the last resort, index.

That order of preference is the template hierarchy. Once you know it, you stop guessing which file to edit.

The idea in one example

Somebody opens a post in the Recipes category. WordPress looks, in this order, for:

  1. single-post-chocolate-cake (that exact post)
  2. single-post (any post)
  3. single (any single entry)
  4. singular (any entry or page)
  5. index (anything)

It uses the first one that exists. If your theme only has index, everything is drawn with it. If tomorrow you add single, posts change and the rest stays as it was.

Classic and block themes

The order is the same in both. What changes is where the templates live.

Classic themeBlock theme
FormatPHP filesHTML files with blocks
FolderThe theme's roottemplates/
Reusable partsheader.php, footer.php, sidebar.phpparts/
EditedWith a code editorIn Appearance → Editor
Examplesingle.phptemplates/single.html

In block themes, changes made in the site editor are saved in the database and win over the theme's files. If you edit the file and nothing happens, that is why: reset the template from the editor.

The whole hierarchy

Read each row from left to right: WordPress goes to the next option if the previous one doesn't exist. They all end in index.

PageOrder
Front pagefront-page → (if it's a page) the page's order, or home
Posts pagehome
Single postsingle-post-{slug} → single-post → single → singular
Custom contentsingle-{type}-{slug} → single-{type} → single → singular
PageChosen template → page-{slug} → page-{id} → page → singular
Categorycategory-{slug} → category-{id} → category → archive
Tagtag-{slug} → tag-{id} → tag → archive
Custom taxonomytaxonomy-{taxonomy}-{term} → taxonomy-{taxonomy} → taxonomy → archive
List of a custom typearchive-{type} → archive
Authorauthor-{name} → author-{id} → author → archive
Datedate → archive
Searchsearch
Not found404
AttachmentBy file type → attachment → single → singular

The official reference, with the drawing that everyone prints, is in the developer handbook.

Two that confuse people

home is not the home page. It is the list of posts. The page your visitors see first is front-page. In Settings → Reading you decide whether the front page shows the latest posts or a fixed page.

page and single are different. page is for pages (About, Contact); single for posts and other content. Both fall back to singular.

How to see which template is in use

  • Block theme: open the page, and in the admin bar click Edit site. The editor opens the template being used.
  • Classic theme: install Query Monitor. Its Template panel shows the file and all the ones WordPress looked for before.
  • Without plugins: look at the classes of the <body> element in the page's source. single-post, category-recipes or page-id-42 tell you what kind of page it is.

Common tasks

A different design for one category

Block theme: Appearance → Editor → Templates → Add template → Category, and choose the category. Classic theme: copy category.php (or archive.php) as category-recipes.php and edit it.

A different design for one page

Block theme: edit the page, open Template in the sidebar and create a new one. Classic theme: create a file with this comment at the top, and it will appear as an option:

<?php
/*
Template Name: Wide landing page
Template Post Type: page
*/
get_header();
while ( have_posts() ) {
  the_post();
  the_content();
}
get_footer();

A useful 404 page

Edit the 404 template: one sentence, the search box and links to your main sections. It is the most forgotten template and one of the quickest to improve.

Products in WooCommerce

WooCommerce has its own templates, which follow the same logic: single-product, archive-product, taxonomy-product_cat. In a classic theme they are copied into a woocommerce folder of the child theme; in a block theme they appear in the editor.

Don't edit the parent theme

An update erases what you changed in its files. Do it in a child theme, where a file with the same name takes precedence. Our guide to child themes explains how to make one in five minutes.

The order between parent and child is worth knowing: specificity wins first. If the parent has single-post.php and the child only single.php, posts use the parent's, because it is more specific.

Parts: what repeats

Header, footer and sidebar are separate pieces that the templates call. In classic themes, with get_header() or get_template_part( 'parts/card' ); in block themes, they are template parts. If what you want to change appears on every page, it is probably in a part and not in a template. For the footer, see how to edit it.

When something doesn't fit

  • You created the file and it isn't used. Check the name: plural, hyphens and slugs must match exactly. Clear the cache.
  • Your archive returns 404. Open Settings → Permalinks and save without changing anything.
  • A page builder ignores the template. Elementor, Divi and others can replace whole templates from their own panel.
  • A plugin imposes its own. Course, event and shop plugins do it; look for their override folder in the documentation.

Try these changes on a staging copy. If you would rather have somebody build the templates, our development team takes on WordPress work like this.

Frequently asked questions

Which file is indispensable?

In a classic theme, style.css and index.php. In a block theme, style.css and templates/index.html.

Can I add levels of my own?

Yes, with the {type}_template_hierarchy filter, for example to look for templates by month or by role.

Related Articles

WordPress Accessibility: EAA & WCAG 2.2 Checklist WordPress Tutorials

WordPress Accessibility: EAA & WCAG 2.2 Checklist

WordPress accessibility checklist for the EAA and WCAG 2.2: fix contrast, keyboard, forms and checkout issues. Start auditing your site today.

Nov 23, 2026
WordPress Plugin Conflicts: Find & Fix Them WordPress Tutorials

WordPress Plugin Conflicts: Find & Fix Them

WordPress plugin conflicts: find the cause and fix it fast with this step-by-step guide. Try Phluit hosting.

Nov 9, 2026
WordPress Maintenance Plan: What Agencies Should Include WordPress Tutorials

WordPress Maintenance Plan: What Agencies Should Include

WordPress maintenance plan essentials for agencies: updates, backups, security. Build yours and explore Phluit hosting today.

Nov 2, 2026