What is the template hierarchy in WordPress?
When a page is requested, WordPress finds out its type (single post, page, category and so on) and looks for a template file in a fixed order, from the most specific name to the most general one. The last choice is always index.php.
| Page | Order of files |
|---|---|
| Single post | single-{post-type}-{slug}.php, single-{post-type}.php, single.php, singular.php, index.php |
| Page | page-{slug}.php, page-{id}.php, page.php, singular.php, index.php |
| Category | category-{slug}.php, category-{id}.php, category.php, archive.php, index.php |
| Front page | front-page.php, then home.php or page.php, index.php |
| 404 | 404.php, index.php |
You can test it with a theme where each file prints its own name. We did exactly that in WordPress Template Hierarchy. In block themes the same logic is used, but with files like templates/single.html.
Learn more about the similar topics:
| Tutorials |
|---|
| WordPress Themes |
| WordPress Top Theme List |
| WordPress Theme Files and Functions |
| WordPress Template Hierarchy |
| WordPress Enqueue Scripts and Styles |
| WordPress Loop |
| WordPress WP_Query Class |