Beginner’s Guide to WordPress Template Hierarchy (cheat sheet) | How to create a website or blog in 2020

After our infographic on how WordPress works behind the scenes, several users asked us to explain how a WordPress theme works behind the scenes.

In this article, we explain WordPress template hierarchy for beginners. This cheat sheet is extremely useful when customizing a template or creating a custom WordPress theme.

Why learn about the WordPress template hierarchy?

All modern WordPress themes consist of templates, stylesheets, javascript and images. Together, these files control the appearance of your website to users.

Relative: 9 things to consider when choosing the perfect WordPress theme for your website.

WordPress has a default template hierarchy. This means that templates with specific filenames affect specific areas of your website. It also tells you what template name to use for a specific element.

Most modern WordPress themes come with templates for displaying categories, dates, files, individual posts, custom pages, and more. As a user, you can create more templates by creating a subtopic.

With that in mind, let’s take a look at how this hierarchy of WordPress templates works behind the scenes.

View WordPress Template Hierarchy (cheat sheet)

WordPress uses an easy to understand and descriptive template name pattern. The following visual cheat sheet explains which template files are used to display different pages on a WordPress site.

Here is a breakdown of WordPress template files to edit for different pages on a typical WordPress site.

What template files does the homepage use?

site home page

WordPress instantly displays your blog posts on your site’s home page. You can also configure it to use a custom home page (also known as a cover page). Configuration »Read Page in the WordPress admin area.

1. front-page.php – If you use a static cover, WordPress will first look for this template file and use it to display the cover.

2. home.php – If you are using a static home page and don’t have a Front Page.php template in your theme, WordPress will look for the home.php template. It is also used to display standard blog posts on the homepage.

3.index.php – If front-page.php or home.php does not exist, WordPress uses the index.php template to display the home page. This template is the default WordPress booking template to display any page.

What template files does a single release use?

Single post page template

WordPress looks for these files to display a single post.

1. single- {post-type} – {slug} .php – Use this template to change the display of a specific single post in any post type. For example, if the post type is “review” and the post slug is “acme-phone”, WordPress will look for “single-review-acme-phone.php”.

2. single-{post-type}.php – WordPress checks if there is a template that displays this specific post type. For example, if the post type is “review”, WordPress will look for “single-review.php”.

3. single.php – WordPress then returns to single.php.

4. singular.php – This template adds another alternative to display a single element of any publication type.

5.index.php – As mentioned above, WordPress eventually returns to index.php.

What template files does a single page use?

Static page template

WordPress pages are one of the standard post types. They allow you to create static pages on your site instead of posts. Read our guide on the difference between posts and pages.

1. Custom Page Template – The page template assigned to the page. Learn how to create a custom page template in WordPress.

2. page- {slug} .php – If the page slug is contact-us, WordPress will try to use page-contact-us.php.

3. page-{id}.php – If the page ID is 17, WordPress will look for a template file named page-17.php.

4.page.php – The template to display all static pages.

5. singular.php – This template is a standard reservation for all elements of a single post type.

6.index.php – The default booking template.

Which template files use category files?

Category file template

WordPress uses these files to display category-related pages in WordPress.

1. category- {slug} .php – This template will display the category archive page for a specific category. For example, if the category slug is Reviews, WordPress looks for the category-reviews.php template.

2. category- {id} .php – WordPress will then look for a template with category ID. For example, if the category ID is 17, WordPress will look for category-17.php.

3.category.php – This is the default template for displaying all category archive pages in WordPress.

4. archive.php – This is the default template used by WordPress to display archive pages.

5.index.php – The default booking template.

Which template files use tag files?

Caption File Template

WordPress uses these files to display tag archive pages.

1. tag- {slug} .php – If the tag slug is fruit, WordPress looks for tag-fruit.php.

2. tag-{id}.php – If the tag ID is 17, WordPress will look for the tag-17.php template.

3. tag.php – The default template for label files.

4. archive.php – The default template for each archival page.

5.index.php – The default booking template.

Which template files use custom taxonomy files?

Custom taxonomy file

Categories and tags are two standard WordPress taxonomies. Users can also create their own custom taxonomies. This is how WordPress looks for templates to display custom taxonomy pages.

1. Taxonomy- {taxonomy} – {term} .php – If you have a custom taxonomy called Genre and there is a term “suspense”, WordPress will look for taxonomy-genre-suspense.php.

2. Taxonomy- {Taxonomy}.php – If the taxonomy was gender, WordPress would look for taxonomy-genre.php.

3. taxonomy.php – The default template for displaying a custom taxonomy file.

4. archive.php – The default reservation for all archive pages in WordPress.

5.index.php– The default booking template in WordPress.

What template files use custom post types?

Custom post type file

This is how WordPress looks for templates to display custom post type files.

1. archive-{post_type}.php – If you have a post type that is reviewed, WordPress searches archive-review.php.

2. archive.php – The default template to display all archive pages in WordPress.

3.index.php – The default booking template in WordPress.

What template files are used to view author files?

Author archive

WordPress generates archive pages for each author on your WordPress site. This is what the template for the author file looks like.

1. author-{nicename}.php – If the author’s pretty name is matt, WordPress will look for author-matt.php.

2. author-{id}.php – If the author’s userid is 6, WordPress will look for author-6.php.

3. author.php – The default template for displaying author archive pages in WordPress.

4. archive.php – The default template to display all archive pages in WordPress.

5.index.php – The default booking template in WordPress.

What template files are used to display date-based files?

File based on date

WordPress also displays your posts on archive pages based on dates for months and years. This is what the templates for these pages look like.

1. date.php – The default template for date-based files.

2. archive.php – The default template for displaying author archive pages in WordPress.

3.index.php – The default booking template in WordPress.

What template files are used to display search pages?

search results page

1. search.php – The default page for displaying search results in WordPress.

2. searchform.php – The template for displaying a search form in WordPress.

3.index.php – The default booking template in WordPress.

What template files are used to display 404 error pages?

404 error page

The 404 error page appears when WordPress cannot find the requested content. Read our guide to improving your 404 page template.

1. 404.php – The default template to display 404 error page in WordPress.

2.index.php – The default booking template in WordPress.

What template files are used to display attached pages?

Attached Pages

1. MIME_type.php – Mime_type means file type. For example image.php, video.php, application.php.

2. attach.php – The default template for displaying attached pages.

3. single-attach.php – To view a single attachment.

4. single.php – The default template for displaying individual post type elements.

5.index.php – The default booking template in WordPress.

What template files are used to display inlays?

Embedded

Since WordPress 4.5 you can use templates to render an embedded post in WordPress.

1. embedded-{post-type} – {post_format}.php – WordPress first looks for a post type and post format template. For example, if you have a video review, WordPress looks for embedded-review-video.php.

2. Embed-{Post-Type}.php – If the post type is review, WordPress would look for embedded-review.php.

3. embedded.php – The standard reserve for all inlays.

We hope this tutorial helped you learn more about the WordPress template hierarchy. You might also want to see our list of the best WordPress drag and drop page builders.

If you enjoyed this article, subscribe to our YouTube channel to watch WordPress tutorial videos. You can also find us on Twitter and Facebook.