It really needs to understand how WordPress renders a page, if you would like to be a master in WordPress. When WordPress renders a page, it checks first from which page it should render and then it does. So the WordPress template hierarchy is very important and everyone who wants to understand WordPress should know about this and how it works.
Most importantly if you want to customize an existing WordPress site of yours then itll help you to customize your site. And youll get the idea which files to edit.
The WordPress Template Hierarchy in detail.
If you would like to see a visual example you can check this out: A visual example
Would you like to interact with the diagram?
If you do then you can also interact with the diagram
Home Page.
By default, WordPress sets your site to display recent blog posts on your homepage.
First check home.php exists or not. If not then WordPress renders the posts from index.php
- home.php
- index.php
Note: If front-page.php exists then home.php wont work. Because itll be overridden.
Frontpage.
It needs to understand carefully. First of all, WordPress will look up if you choose any static page to show a home page ( settings ? reading ). If not set then itll look up if front-page.php exists or not, if its then itll render your homepage from front-page.php. And if not itll use home.php. If even home.php doesnt exist then itll show render your homepage from index.php.

- front-page.php can be used for both ( your latest or static page ).
- home.php if front-page.php doesnt exist or if you dont set a static page then WordPress render homepage from it.
- index.php if both pages ( mention above ) doesnt exist then WordPress renders your homepage from index.php.
WordPress page ( single page )
First of all, WordPress lookup page.php to render a page ( page is also a post type ). If page.php doesnt exist then WordPress renders your websites page from index.php.
Lets take a look at how WordPress template hierarchy works on page
- page.php is normally used to render your website page.
- page-{id}.php is used to render a specific page. Such as if you would like to customize a specific page then you can make a page providing its id such as page-22.php. Itll render only a page that contains ID of 22.
- page-{slug}.php you can set a custom slug to render a specific page that contains that slug. Such as a page contains ( our-latest-event ) slug. So you can make a page of page-our-custom-event.php which will render only that page.
- singular.php is used to render a page if page.php doesnt exist.
Custom Template file for more details, check out this: custom page in WordPress site
WordPress post ( single post )
A single post template is used to render a single post. It can be either a blog post or a custom post type.
By default, WordPress shows any kind of a single post from single.php but we can also specify a template for a specific post type.
- single-{post-type}.php if you want to specify a single template for a post type, then you can follow this way ? single-custom-post-type.php ( just need to use post type slug ). Thats it. Itll render this custom post type from this page.
- single-{post-type}-{slug}.php is used to render a specific slug of a specific post type. Such as you have a custom post with hello-world slug. Then you can use a template to render this post only in this way: single-your-post-type-hello-world.php
- single.php WordPress renders single post from this template if the above-mentioned files dont exist.
- singular.php WordPress renders a single post from this template if page.php even doesnt exist.
WordPress category and tag page ( Tag and Category )
To understand the WordPress template hierarchy its really important to know how tag and category page works. Ive combined them together so that you can easily understand.
category.php is used to render the category of your site and tag.php is used to render all of the tags of your site. But we can customize them too.
- category-{slug}.php is used to render a specific category with slug such as I have a category slug event so we can follow this way: category-event.php and tag-{slug}.php are also like that to render a specific tag. Such as tag-your-slug.php.
- category-{id}.php is used to render a specific category with slugs such as category-33.php and tag-{id}.php works also like that, such as tag-44.php.
- If these above-mentioned files dont exist then WordPress renders category from category.php similarly for the tag, WordPress renders tag from tag.php
WordPress author page.
Accordance with WordPress template hierarchy WordPress looks after a file called author.php to render author archive. But we can customize it as we want.
- WordPress renders author post from author.php by default.
- We can specify the author page with authors nickname such as author-nickname.php
- We can also use author ID such as author-3.php
- If any of above-mentioned page doesnt exist then WordPress renders author archive from archive.php
- If archive.php doesnt exist then WordPress renders author archive from index.php
WordPress search result
- If you want to specify a page for only search result then you can make a template called search.php
- If this page doesnt exist then WordPress renders search result from index.php
WordPress 404 not found page.
- 404.php is used to render if the user visits accidentally any wrong page.
- If its not found then WordPress renders it from index.php
Do you know how to work with WordPress Post excerpt?
Here we have written an article on how to work with WordPress post excerpt
Found this article useful?
please follow us on Facebook and Instagram
0 comments