What Is Template Hierarchy in WordPress?
Ahsan Parwez
HostWP Expert
The template hierarchy is the decision tree WordPress follows to pick which theme file renders a page. It looks for the most specific template first, then falls back to more general ones until it finally reaches index.php.
Detailed Answer
-
Every theme relies on this hierarchy to decide what you actually see in the browser. Here is what you need to know:
- How it works: WordPress checks the request type, then hunts for the most specific file. For a single post it tries single-post.php, then single.php, then singular.php, and finally index.php. The first match wins.
- Common examples: Category pages look for category-slug.php before category.php, static pages check page-slug.php before page.php, and missing pages fall back to 404.php.
- Why it matters: It lets you customize one specific page, post type, or category without touching the rest of your site. Just create the more specific file and WordPress picks it up automatically.
- The catch: In block themes, this classic PHP hierarchy is largely replaced by HTML templates and theme.json, so the file you expect to control a page may not be the one actually loading.
I usually describe this as WordPress asking “got anything more specific?” until it hits index.php. Once it clicks, debugging weird layout issues gets way easier. Just remember block themes play by different rules, so don’t waste an hour editing a PHP file that isn’t even being used.
Our WordPress expert are here to help you 24/7.
On this page
Related Questions
Expert WordPress Support Engineers Available 24/7
90 sec
Average
Response Time
98 %
Customer
Rating
24/7
Expert
Support

