Skip to content

WordPress Template Hierarchy

The Template Hierarchy in WordPress is a system that determines which template files are used to display content on your site. WordPress uses a set of rules to choose the appropriate template based on the type of content being requested.

Understanding the template hierarchy is essential for customizing your WordPress theme, as it allows you to control how different pages, posts, categories, archives, and other content types are displayed. The hierarchy follows a specific order, where WordPress looks for a template file that matches the current request, from most specific to most general.

You can find more here

When WordPress needs to render a page, it follows a set order to find the correct template. Below is an overview of the typical template files WordPress will look for, starting with the most specific:

  1. Custom Templates (Custom Post Types, etc.)
    WordPress first looks for a custom template for specific content types. For example, if you are viewing a custom post type like “movie,” WordPress will look for:

    • single-movie.php (for individual movie posts)
    • archive-movie.php (for movie archive pages)
  2. Single Post Template
    If no custom template is found, WordPress will then search for the template for a single post:

    • single.php (for individual posts)
  3. Page Template
    WordPress will then check for a template for a static page:

    • page.php (for individual static pages)
  4. Category Template
    If you’re viewing a category archive, WordPress will look for:

    • category-{slug}.php (for a category with a specific slug)
    • category-{ID}.php (for a category with a specific ID)
    • category.php (fallback for category pages)
  5. Tag Template
    If you’re viewing a tag archive, WordPress will look for:

    • tag-{slug}.php (for a specific tag)
    • tag-{ID}.php (for a specific tag ID)
    • tag.php (fallback for tag pages)
  6. Date-based Archive Template
    For archive pages based on dates (like by year or month), WordPress will search for:

    • date.php (for date-based archives)
  7. Author Template
    If you’re viewing content by a specific author, WordPress looks for:

    • author-{ID}.php (for a specific author’s archive)
    • author.php (fallback for author pages)
  8. Search Template
    If you’re viewing a search results page, WordPress looks for:

    • search.php (for search results pages)
  9. 404 Template
    If WordPress can’t find a specific template or content for the request, it will use the 404 template:

    • 404.php (for not-found pages)

Here’s a simplified version of how WordPress checks templates for various content types:

  • Single Post:
    single-{post-type}.phpsingle.phpindex.php

  • Page:
    page-{slug}.phppage-{ID}.phppage.phpindex.php

  • Category:
    category-{slug}.phpcategory-{ID}.phpcategory.phpindex.php

  • Tag:
    tag-{slug}.phptag-{ID}.phptag.phpindex.php

  • Custom Post Type:
    single-{custom-post-type}.phpsingle.phpindex.php


You can find more here