You edited single.php, reloaded the post, and nothing changed. That is almost always the template hierarchy: WordPress decided the URL was something else, or it found a more specific file first, or the theme is a block theme and the PHP file you edited was never in the running. The hierarchy is not a mystery — it is a deterministic, ordered list of filenames that WordPress builds for every request and then walks top to bottom until one exists. Once you can print that list for a given URL, “which file renders this page” stops being guesswork and overrides stop landing in the wrong place.
What you’ll accomplish
- Print the exact ordered candidate list WordPress builds for any URL on your site, instead of guessing from a chart.
- Log the file that actually rendered a request, including when a plugin has redirected it.
- Place a classic-theme override in the child theme so it wins, and know why a more specific file beats it.
- Read block theme resolution: how
templates/*.htmlslugs map onto the same hierarchy, and why database-stored customizations beat theme files. - Recognise the four common cases where the hierarchy is not the thing that is wrong.
Prerequisites
- WordPress 6.0 or later. Everything below applies to 5.9+ as well, but two things shifted before that:
singular.phparrived in 4.3, and custom page templates became assignable to any post type (not just pages) in 4.7. - Filesystem access to
wp-content/themes/andwp-content/mu-plugins/, plus WP-CLI on the same host. SFTP-only access will work for the file edits but not for the CLI checks. - A staging or local copy. Two of the steps drop a must-use plugin and write to the debug log; neither is something to do first on production.
- Block theme readers: WordPress 5.9 renamed the block theme folders from
block-templates/andblock-template-parts/totemplates/andparts/. Themes written against 5.8 may still use the old names; core reads both, but every path in this guide uses the current ones. - If you are not sure which theme system you are on, step 1 answers it in one command. The distinction changes the answer to almost every question here, so start there.
How it works
WordPress resolves a request in three phases, and the hierarchy is only the second one.
First, the rewrite rules turn the URL into query variables, and WP_Query runs. The result is a set of conditional flags: is_single(), is_page(), is_category(), is_404(), and so on. Exactly one of these decides the branch — the hierarchy is a consequence of the query, never of the URL string. A permalink of /blog/hello-world/ might be a post, a page, or a 404 depending on what is in the database, and each one takes a different branch.
Second, wp-includes/template-loader.php runs an ordered if/elseif chain over those conditionals and calls the matching helper: get_single_template(), get_page_template(), get_category_template(). Each helper builds an array of candidate filenames from most specific to least, then hands it to get_query_template(). That function applies the {$type}_template_hierarchy filter to the array, calls locate_template(), and applies the {$type}_template filter to the result.
Third, locate_template() walks the array in order and returns the first filename that exists on disk. For every candidate it checks the child theme folder before the parent theme folder. That is the whole override mechanism: a file with the same name in the child theme is found first and wins.
Two consequences fall out of this design. Specificity beats location: single-post.php in the parent theme beats single.php in the child theme, because the loop is over candidates on the outside and folders on the inside. And every branch terminates at index.php, which is why a theme containing nothing but index.php and style.css is a valid theme that renders every URL on the site.
Step-by-step
1. Determine which theme system you are on. Everything downstream depends on this, and the answer is not the theme’s name:
wp theme list --status=active --field=name
wp eval 'var_dump( wp_is_block_theme() );'
twentytwentyfive
bool(true)
wp_is_block_theme() returns true when the active theme contains templates/index.html. That single file is what flips WordPress into block resolution — not a setting, not a theme tag.
2. Log the file that actually rendered a request. template_include is the last filter before the file is loaded, so whatever it returns is the truth. Create wp-content/mu-plugins/sh-template-probe.php:
<?php
add_filter( 'template_include', function ( $template ) {
error_log( 'template_include -> ' . $template );
return $template;
}, 9999 );
error_log() only lands somewhere useful if debug logging is on, so confirm that first:
wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_LOG true --raw
curl -s -o /dev/null https://staging.example.com/blog/hello-world/
tail -n 1 wp-content/debug.log
[07-Aug-2026 14:02:11 UTC] template_include -> /var/www/html/wp-content/themes/mytheme-child/single.php
If a block theme is active you will see wp-includes/template-canvas.php here instead. That is expected and is covered in step 5.
3. Print the whole candidate list, not just the winner. The {$type}_template_hierarchy filter fires once per request with the full ordered array. Register it for every branch by appending this to the same must-use plugin, below the code from step 2 and without a second opening tag:
$sh_types = array(
'404', 'archive', 'attachment', 'author', 'category', 'date',
'embed', 'frontpage', 'home', 'index', 'page', 'privacypolicy',
'search', 'single', 'singular', 'tag', 'taxonomy',
);
foreach ( $sh_types as $sh_type ) {
add_filter( "{$sh_type}_template_hierarchy", function ( $templates ) use ( $sh_type ) {
error_log( "hierarchy [{$sh_type}] " . implode( ' > ', $templates ) );
return $templates;
} );
}
curl -s -o /dev/null https://staging.example.com/blog/hello-world/
grep 'hierarchy \[' wp-content/debug.log | tail -n 2
[07-Aug-2026 14:06:40 UTC] hierarchy [single] single-post-hello-world.php > single-post.php > single.php
[07-Aug-2026 14:06:40 UTC] hierarchy [singular] singular.php
Two lines, not one, because template-loader.php tried is_single() first and fell through to is_singular(). index.php never appears in these arrays — it is the hard-coded final fallback in template-loader.php rather than a candidate.
4. Place a classic-theme override where it wins. Now that you know the candidate names, pick the one that matches the scope you want and put it in the child theme:
cp wp-content/themes/mytheme/single.php \
wp-content/themes/mytheme-child/single-post.php
grep -c . wp-content/themes/mytheme-child/single-post.php
84
single-post.php sits above single.php in the list, so it now wins for every post while leaving custom post types on the parent’s single.php. If you want the narrower scope, name it single-post-hello-world.php instead. Re-run step 2 and the logged path should change to the new file. If it does not, see troubleshooting.
5. Read block theme resolution. Block themes use the same candidate list, minus the extension. Inside get_query_template(), core calls locate_block_template(), which strips .php from each candidate, looks for a matching block template by slug, and returns wp-includes/template-canvas.php when it finds one. The canvas is a thin PHP file whose only job is to render the block markup that was stashed in $_wp_current_template_content.
ls wp-content/themes/twentytwentyfive/templates/
404.html home.html page-no-title.html search.html
archive.html index.html page.html single.html
Most filenames are the hierarchy slugs you logged in step 3 with .html in place of .php. The exception is page-no-title.html, a custom template an editor picks per page rather than a hierarchy slug. There is no singular.html, so a post resolves to single.html and a page to page.html. To override, drop templates/single-post.html into the child theme — same specificity rule, same child-first lookup.
6. Find database templates that beat your files. Anything edited in the Site Editor is stored as a wp_template post and takes priority over the theme file with the same slug. This is the single biggest source of “my file edit did nothing” in block themes:
wp post list --post_type=wp_template --post_status=publish \
--fields=ID,post_name,post_title
+-----+-------------+---------------+
| ID | post_name | post_title |
+-----+-------------+---------------+
| 412 | single | Single Posts |
| 418 | page | Pages |
+-----+-------------+---------------+
Those two slugs are now served from the database. In the Site Editor, the template shows a Reset or Clear customizations action; from the CLI, deleting the post has the same effect and is permanent:
wp post delete 412 --force
Success: Deleted post 412.
Validate it works
Pick one URL and confirm the whole chain end to end. With the probe from step 2 still in place, request the page and read the last log line:
curl -s -o /dev/null https://staging.example.com/blog/hello-world/
grep -E 'hierarchy \[single\]|template_include' wp-content/debug.log | tail -n 2
[07-Aug-2026 14:21:03 UTC] hierarchy [single] single-post-hello-world.php > single-post.php > single.php
[07-Aug-2026 14:21:03 UTC] template_include -> /var/www/html/wp-content/themes/mytheme-child/single-post.php
The check that matters is that the returned path is the first candidate in the list that actually exists on disk. If a candidate above the winner exists but was skipped, something is filtering the result. If the returned path is not in the candidate list at all, a plugin has overridden template_include outright.
Then remove the probe so it does not sit in production:
rm wp-content/mu-plugins/sh-template-probe.php
wp config set WP_DEBUG false --raw
Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the value false.
Troubleshooting
The edit does nothing and the logged path is a different file. A more specific candidate exists somewhere. Compare the logged path against the candidate list from step 3: if the winner is single-post.php and you edited single.php, the parent theme shipped the more specific file. Specificity beats the child theme, always.
The logged path is template-canvas.php and PHP edits are ignored. The theme is a block theme. Your .php file is only consulted when no block template matches at equal or higher specificity, and even then, a wp_template database post outranks both. Work in templates/*.html and check step 6.
page-about.php is ignored on a page whose slug is about. A custom template assigned to that page beats slug-based candidates. Check the page’s Template setting in the editor, or wp post meta get <ID> _wp_page_template from the CLI — anything other than default means a named template file is first in the list.
Changes to the home page go nowhere. The front page has its own branch. If Settings > Reading is set to a static page, front-page.php is tried first, then the page hierarchy for that page; home.php only applies to the posts index. Confirm with wp option get show_on_front before touching either file.
The file exists but is never picked up. Check case and permissions first — Single-Post.php will not match on a case-sensitive filesystem, and a file the web server cannot stat does not exist as far as locate_template() is concerned. Then clear OPcache; a stale cached copy of an old template is a common cause on tuned hosts.
When this is the wrong approach
The hierarchy answers “which file renders this URL.” It does not answer “why does this page show the wrong posts” — that is WP_Query and pre_get_posts, one phase earlier, and no amount of template surgery will fix a query problem. It also does not help when the goal is a variant of one existing layout for a handful of pages; a custom page template selected per page, or conditional logic inside the existing file, is less to maintain than five near-identical templates. And if you are adding a new template file to a theme you did not write and do not control updates for, put it in a child theme first. See creating a WordPress child theme, and block themes vs classic themes if you are still deciding which system to build on. The full per-branch candidate charts live in the official template hierarchy documentation.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under enterprise WordPress operations; book an infrastructure consult.