WordPress GuideDevelopment → Template Hierarchy

WordPress template hierarchy explained for new developers

A man looking thoughtfully at a laptop screen.

If you’re building or customizing themes, understanding WordPress’ template hierarchy is essential. It’s the system WordPress uses to decide which PHP file to load when rendering a given page. Once you understand the logic, you can build custom templates that match specific content types, categories, or even post slugs—without writing extra conditional code.

Let’s break it all down and walk through exactly how it works.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

What is the WordPress template hierarchy?

WordPress doesn’t just randomly choose which template file to use—it follows a strict hierarchy. This system checks the context of the current request (like a single post, a page, a category archive, etc.) and selects the most specific matching template available in your theme folder.

If it doesn’t find a file that fits perfectly, it falls back to more general ones until it reaches index.php, the default catch-all.

Example: Someone visits a category archive for “News.” WordPress looks for:

The core logic behind the hierarchy

WordPress determines the type of query being requested based on the URL or internal logic. It could be:

For each of these, WordPress checks the most specific template, then falls back layer by layer.

Let’s break it down with real file names.

Template hierarchy breakdown by page type

Each of these sections explains the hierarchy in order, from most specific to most general.

Front page

If you’ve set a static front page in Settings > Reading:

If your homepage is the blog listing:

Single post

For standard blog posts:

Custom post type (CPT)

For example, if you register a post type called event:

Static page

For individual pages:

Category archive

When visiting a category archive:

Tag archive

For tag pages:

Author archive

For author profile pages:

Date archive

For year/month/day archive URLs:

Search results

For search result pages:

404 error

If no content matches the query:

Visualizing the hierarchy

The hierarchy isn’t something you need to memorize completely. One of the most helpful resources is the WordPress template hierarchy diagram, a flowchart-style overview of how WordPress picks templates.

You can also use tools like What The File (a browser extension) to inspect which template is being used on a live site.

Using template parts for reusable code

While the template hierarchy picks the main file, you can use get_template_part() to include reusable components inside those files. For example:

<?php get_template_part(‘partials/content’, get_post_type()); ?>

This will include partials/content-post.php or partials/content-event.php based on the post type.

It’s great for modularizing your theme—headers, footers, navigation, loops, and more can live in separate files, making your code cleaner and easier to manage.

Best practices for working with the hierarchy

Ready to get started?

Get the fastest, most secure WordPress.org hosting on the market.

Additional resources

What is managed WordPress hosting? →

Get details and decide if managed WordPress hosting is right for you.

What is the WordPress loop? →

Learn how the WordPress Loop works to display posts dynamically on your website.






A complete guide to WordPress shortcodes →

Shortcodes make life easier. Learn how to get started!

Trust us to help you choose the ideal hosting solution

Loading form…