Concept Flow - Template hierarchy
Request URL
Check for specific template
front-page.php
index.php
Render Output
WordPress checks templates from most specific to general, using the first matching template file to render the page.
Jump into concepts and practice - no test required
<?php if (is_front_page()) { get_template_part('front-page'); } elseif (is_single()) { get_template_part('single', get_post_type()); } else { get_template_part('index'); } ?>
| Step | Condition Checked | Result | Template Chosen | Action |
|---|---|---|---|---|
| 1 | Is front page? | Yes | front-page.php | Load front-page.php template |
| 2 | Is single post? | No | - | Skip single post templates |
| 3 | Is category archive? | No | - | Skip category templates |
| 4 | Is page? | No | - | Skip page templates |
| 5 | Fallback | - | index.php | Load index.php as fallback |
| 6 | Render | - | - | Output page using front-page.php |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|---|
| Template chosen | none | front-page.php | front-page.php | front-page.php | front-page.php | front-page.php |
WordPress Template Hierarchy:
- WordPress checks templates from most specific to general.
- It uses front-page.php for the homepage.
- For single posts, it tries single-{post-type}.php.
- If no specific template matches, it falls back to index.php.
- The first matching template stops the search and renders the page.single-{post-type}.php to display a single post of a custom or default post type.single.php or index.php, but the first choice is single-{post-type}.php.single-{post-type}.php -> Option Dsingle-{post-type}.php first [OK]single-{post-type}.php first [OK]page.php with single post templatearchive.php is for single postsindex.php is always used firstcategory-{slug}.php to display a specific category archive page.category-news.php.category-news.php -> Option Bcategory-{slug}.php [OK]category-{slug}.php [OK]archive-news.php which is invalidcategory.php as specific slug templatenews.php which is not recognizedpage-about.php, page.php, and index.php. Which template will WordPress use to display the About page?page-{slug}.php first for pages, so page-about.php matches the About page slug.page-about.php exists, WordPress uses it before falling back to page.php or index.php.page-about.php -> Option Apage-about.php have priority [OK]page.php ignoring slug-specific templateindex.php is used firstsingle-post.php but WordPress still uses single.php to display posts. What is the likely problem?single-{post-type}.php where {post-type} matches the post type slug exactly.single-post.php is correct if the post type is 'post'. But if the post type is custom or named differently, the file name must match exactly.single-post.php, it may be because the post type slug is not 'post' or the file is misplaced.single-{post-type}.php -> Option Asingle-{post-type}.php exactly to post type slug [OK]single-post.php always works for postssingle-{post-type}.php filestag-{slug}.php for tag archive pages with specific slugs.tag-featured.php.tag-featured.php is missing, WordPress falls back to tag.php or archive.php.tag-featured.php -> Option Ctag-{slug}.php [OK]tag-{slug}.php for custom tags [OK]archive-featured.php which is invalidtaxonomy-featured.php with tag templatetag.php is always used for all tags