WP Template Hierarchy Checklist for Classic and Block Themes

The WordPress (WP) template hierarchy is the fixed list of file names WordPress checks, from the most specific to the most general, to decide which theme file renders the current URL. It loads the first file that exists, so a single post in a theme with single.php skips singular.php and index.php entirely. If no specific file matches, everything falls back to index.php.

That single rule explains most of the surprises you’ll meet when building a custom theme. Below is a checklist of theme files, context by context, followed by the reasons the wrong template loads and how to find out which file WordPress actually picked.

How WordPress chooses the template file

The mechanism takes three steps. First, WordPress parses the URL and runs the main query, which sets conditional tags such as is_single(), is_page() or is_category(). Then wp-includes/template-loader.php walks through those conditionals in a fixed order and builds a list of candidate file names for the first one that is true. Finally, locate_template() returns the first candidate it finds on disk, and WordPress includes it.

The order of those checks matters more than most guides admit. WordPress tests for a 404 before a search, a search before the front page, and the front page before the blog index. So a front-page.php file wins over every page template for the site root. Without that file, WordPress moves on, and a static front page falls back to the page hierarchy.

Child themes fit into the same loop. For each candidate name, WordPress looks in the child theme folder first, then in the parent theme, and only then moves to the next name. So a parent’s category-news.php beats a child’s category.php, which catches many people out. Related reading: Understanding the WordPress Theme Hierarchy.

wordpress theme files

Checklist for the front page and singular templates

Each list runs from the file WordPress tries first to its last resort. Tick the files your theme really needs; you never have to create all of them.

Front page and blog posts index

  1. front-page.php, used for the site root whatever the Reading settings say
  2. home.php, when the front page shows your latest posts
  3. the page hierarchy below, when the front page is a static page
  4. index.php

The blog posts index on its own (for example /blog/, set under Settings > Reading) uses home.php, then index.php. Many people expect home.php to style the homepage; in WordPress terms, “home” means the posts index.

Single posts and custom post types

  1. a custom template chosen in the editor (the $custom.php slot)
  2. single-{post-type}-{slug}.php
  3. single-{post-type}.php
  4. single.php
  5. singular.php
  6. index.php

Example: a product custom post type (CPT, a content type you register beyond posts and pages) gets its own layout through single-product.php. A standard blog post looks for single-post.php before single.php.

Pages

  1. the page template assigned in the editor
  2. page-{slug}.php, for example page-contact.php
  3. page-{id}.php, for example page-7.php
  4. page.php
  5. singular.php
  6. index.php

A custom page template is any theme file whose header contains a Template Name: comment. Since WordPress 4.7, a Template Post Type: line makes the same template available to posts and custom post types too.

Attachments

Media attachment pages first try MIME-based names such as image.php or video.php, then attachment.php, then the single post chain. Most custom themes can ignore them. The same instinct shows in the work of a design studio worth a look.

checklist for archives search and 404 pages

Checklist for archives, search and 404 pages

Category and tag archives

  1. category-{slug}.php or tag-{slug}.php
  2. category-{id}.php or tag-{id}.php
  3. category.php or tag.php
  4. archive.php
  5. index.php

Custom taxonomy archives

  1. taxonomy-{taxonomy}-{term}.php
  2. taxonomy-{taxonomy}.php
  3. taxonomy.php
  4. archive.php
  5. index.php

Post type, author and date archives

  • Custom post type archive: archive-{post_type}.php, archive.php, index.php
  • Author: author-{nicename}.php, author-{id}.php, author.php, archive.php, index.php
  • Date: date.php, archive.php, index.php

A post type archive only exists if register_post_type() sets has_archive to true. Without it, archive-product.php never loads, however carefully you name it.

Search results and 404

  • Search: search.php, then index.php
  • Not found: 404.php, then index.php

Both chains are short, so a theme without these two files shows search results and errors in the generic index.php layout. We’d create both in any client theme: a helpful 404 page with a search form keeps visitors on the site.

why the wrong template loads

Why the wrong template loads

When your edit doesn’t show up, WordPress is almost always loading a more specific file than the one you changed. These are the usual cases, written as symptom, cause and fix.

  • You edit single.php and nothing changes. A single-post.php, a custom template assigned in the editor, or the same file in the parent theme wins first. Check the editor’s Template setting and both theme folders.
  • page-about.php stopped working. Someone changed the page slug. Slug-based files break silently on a rename, so prefer an assigned page template for pages that clients may rename.
  • home.php styles the blog, not the homepage. That’s by design. Use front-page.php for the site root.
  • A new custom post type returns 404. The rewrite rules (WordPress’s URL patterns) don’t know it yet. Save Settings > Permalinks once to flush them.
  • The live site still shows the old layout. A page cache serves stored HTML, so PHP templates don’t run for those visitors. Purge the cache before you debug the hierarchy.
debugging checklist which file is wordpress using

Debugging checklist: which file is WordPress using?

  1. Read the body classes. If the theme calls body_class(), the <body> tag lists the context: single-post, page-id-7, category-news or page-template-…. That tells you which branch of the hierarchy applies.
  2. Install Query Monitor. This free debugging plugin shows the template file in use, the full list of candidates WordPress considered, and the template parts loaded.
  3. Print the template in development. The template_include filter receives the path of the chosen file. It runs just before WordPress includes that file:
    add_filter( 'template_include', function ( $template ) {
        if ( current_user_can( 'manage_options' ) ) {
            error_log( 'Template: ' . $template );
        }
        return $template;
    } );

    Always return $template. Otherwise the page renders blank.

  4. Change the candidate list if you must. Since WordPress 4.7, filters named {$type}_template_hierarchy (for example single_template_hierarchy) let you add or reorder names before WordPress searches for them.

Plugins such as WooCommerce also hook into template_include, so a plugin can override your carefully named file. Query Monitor makes that visible in seconds.

Block themes versus classic themes

Block themes use the same names with an .html extension inside a templates/ folder: templates/single.html, templates/page.html, templates/index.html. The resolution order is identical, and a block theme needs only style.css and templates/index.html to work, just as a classic theme needs style.css and index.php.

The difference is where a template can live. Someone may edit a template in the Site Editor (Appearance > Editor > Templates). WordPress then saves that version in the database, and it overrides the file in your theme.

That’s the block theme version of “I edited the file and nothing changed”: reset the template’s customizations in the Site Editor, and your file takes over again. Full Site Editing reached WordPress core in version 5.9, after a long trial period in the Gutenberg plugin. patoniqwebstudio.com goes into the numbers.

On the editor side, the post or page sidebar shows a Template row. A page with no custom template shows the default “Pages” template, which maps to page.html.

The five theme files to create first

For a custom WordPress design, start with index.php, single.php, page.php, archive.php and 404.php (or their .html twins), and add front-page.php if the homepage differs from the blog. Then add a specific file only when a real page needs a different layout, and check it with Query Monitor the moment you create it. A lean WP template hierarchy is easier to hand over and much harder to break.

Planning a theme from scratch? Map each page type of your site against the checklists above before you write a line of markup. There’s a good explainer over at kinsta.com.