WordPress Template Hierarchy

written by: Jeff McNear

The WordPress core code contains query strings to decide which template or set of templates should be used to display the page which searches down through the template hierarchy until it finds a matching template file.

To determine which template file to use, WordPress will match every query string to a query type to decide which page is being requested (for example, a search page, a category page, etc). Core code selects the template in the order determined by the template hierarchy by looking for template files with specific names in the current theme’s directory using the first matching template file as specified by the hierarchy.

Most templates will pull in files for the sidebar, header & footer


<?php get_sidebar();?>


<?php get_header(); ?>


<?php get_footer();?>

With the main content body being handled by a hierarchy of named files:

The “preference hierarchy” by condition is as follows:


  1. front-page.php
  2. home.php
  3. page.php
  4. index.php

Single post

  1. single-{post-type}.php
  2. single.php
  3. singular.php
  4. index.php

Single page

  1. page-{slug}.php
  2. page-{template-name}
  3. page.php
  4. singular.php
  5. index.php

Category archives

  1. category-{slug}.php
  2. category.php
  3. archive.php
  4. index.php

Custom Taxonomies

  1. taxonomy-{taxonomy}.php
  2. taxonomy.php
  3. archive.php
  4. index.php

Tag archives

  1. tag-{slug}.php
  2. tag.php
  3. archive.php
  4. index.php

Author archives

  1. author-{nicename}.php
  2. author.php
  3. archive.php
  4. index.php

Date-based archives

  1. date.php
  2. archive.php
  3. index.php

Search pages

  1. search.php <= results
  2. searchform.php <= search form

404 error pages

  1. 404.php
  2. index.php

Attachment pages

  1. attachment.php – The attachment pages are displayed using this default template.
  2. single-attachment.php – for displaying single attachment
  3. single.php – the single post type items are displayed using this default template
  4. index.php – The ultimate default