Performance: Template hierarchy
This affects page load speed by determining which template files WordPress loads to render a page, impacting server processing and response time.
Jump into concepts and practice - no test required
Creating specific templates for content types (e.g., single.php, page.php) so WordPress finds the correct template immediately.Using many unnecessary template files or fallback templates causing WordPress to check multiple files before rendering, e.g., relying on generic index.php for all pages.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Generic index.php fallback for all pages | N/A (server-side) | N/A | N/A | [X] Bad |
| Specific templates per content type | N/A (server-side) | N/A | N/A | [OK] Good |
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