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.

PageOrder of files
Single postsingle-{post-type}-{slug}.php, single-{post-type}.php, single.php, singular.php, index.php
Pagepage-{slug}.php, page-{id}.php, page.php, singular.php, index.php
Categorycategory-{slug}.php, category-{id}.php, category.php, archive.php, index.php
Front pagefront-page.php, then home.php or page.php, index.php
404404.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
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.