WordPress Template Heirarchy

If you have a question, “how does WordPress figure out which template file to Use for Rendering the View?” here is the answer. WordPress theme has a hierarchy of template files and the index.php is the most important and required file.
If your theme doesn’t find any requested file, it moves down its hierarchy of template files to find the next most appropriate file to use.

Displaying a unique template file, you can create a file with a unique name. For example, If you want to render the view for a Category #786 of your blog, create a file with this name category-786.php, and WordPress will automatically use it.

Let’s take a look at the hierarchy flowchart below. In this table, you will understand the WordPress template hierarchy in detail.

Which Template File will WordPress Use

The Template Hierarchy

PAGE TYPEtries first>tries nexttries last
ATTACHMENT{mime-type}.php>attachment.phpsingle.php >index.php
PAGE{custome-template}.php>page-{slug}.phppage-{id}.php>page.php >index.php
AUTHORauthor-{author-nicename}.php>author-{author-id}.phpauthor.php >archive.php>index.php
Noor Mustafa Raza

Noor Mustafa Raza

I am a WordPress Developer and Designer, author @WPArena. I am providing Free WordPress consultation and can help you to install WordPress in a secure way to small businesses and bloggers.

Leave a comment

Your email address will not be published. Required fields are marked *