The basics about WordPress template hierarchy
The template files have a big role in WordPress. We use different template files to render the whole WordPress site.
The WordPress have a predefined template hierarchy. That means, to render a specific type page, WordPress always look some template file & if it is absent, then it use another template file.
If we want to deal with themes in WordPress, having a basic idea about these template hierarchy will be useful. Actually, the themes are a collection of template files with some extra files like images etc.
The important template files used in WordPress themes are header.php
, footer.php
, index.php
, single.php
, page.php
, archive.php
& 404.php
etc.
Some of these files are used to render the part of web page like header.php
& footer.php
etc. Some others have predefined function in WordPress site.
Now we can check the priority of these files to render different type pages in WordPress.
I just copied all these information from WordPress Codex. All credits are going to WordPress & its amazing documentation team. My role is only filter that Codex page & republish the essential content.
404 (Not Found) display
Template file used to render a Server 404 error page
- 404.php
- index.php
Search Result display
Template file used to render a Search Results Index page
- search.php
- index.php
Custom Taxonomies display
Template file used to render the Archive Index page for a Custom Taxonomy
- taxonomy-{taxonomy}-{term}.php – If the taxonomy were sometax, and taxonomy’s term were someterm WordPress would look for taxonomy-sometax-someterm.php.
- taxonomy-{taxonomy}.php – If the taxonomy were sometax, WordPress would look for taxonomy-sometax.php
- taxonomy.php
- archive.php
- index.php
Home Page display
Template file used to render the Blog Posts Index, whether on the site front page or on a static page.
- home.php
- index.php
Attachment display
Template file used to render a single attachment (attachment post-type) page
- MIME_type.php – it can be any MIME type (image.php, video.php, application.php). For text/plain, in order:</p>
- text.php
- plain.php
- textplain.php
- attachment.php
- single-attachment.php
- single.php
- index.php
Single Post display
Template file used to render a single post page.
- single-{post_type}.php – If the post type were product, WordPress would look for single-product.php.
- single.php
- index.php
Page display
Template file used to render a static page (page post-type)
- custom template file – The Page Template assigned to the Page. See getpagetemplates().
- page-{slug}.php – If the page slug is recent-news, WordPress will look to use page-recent-news.php
- page-{id}.php – If the page ID is 6, WordPress will look to use page-6.php
- page.php
- index.php
Category display
Template file used to render a Category Archive Index page
- category-{slug}.php – If the category’s slug were news, WordPress would look for category-news.php
- category-{id}.php – If the category’s ID were 6, WordPress would look for category-6.php
- category.php
- archive.php
- index.php
Tag display
Template file used to render a Tag Archive Index page
- tag-{slug}.php – If the tag’s slug were sometag, WordPress would look for tag-sometag.php
- tag-{id}.php – If the tag’s ID were 6, WordPress would look for tag-6.php
- tag.php
- archive.php
- index.php
Author display
Template file used to render an Author Archive Index page
- author-{nicename}.php – If the author’s nice name were rami, WordPress would look for author-rami.php.
- author-{id}.php – If the author’s ID were 6, WordPress would look for author-6.php.
- author.php
- archive.php
- index.php
Date display
Template file used to render a Date-Based Archive Index page
- date.php
- archive.php
- index.php
Archive display
Template file used to render the Archive Index page for a Post Type
- archive-{post_type}.php – If the post type were product, WordPress would look for archive-product.php.
- archive.php
- index.php
These are the file hierarchies to render different type pages in a WordPress site. As stated above, all of this informations are copied from WordPress Codex. You can read the original document at there.
Any way, I believe that this quick reference will help us in our feature WordPress development. Thanks to WP & its Codex.
Got a project in mind? Send me a quick message, and I'll get back to you within 24 hours!.
Recent Posts
- Disabling Payment Methods in WooCommerce Based on Conditions
- How to Update Product Quantity in WooCommerce Using Custom Code
- Dynamically Generating a Table of Contents in WordPress
- Direct Checkout in WooCommerce - Add Product to Cart from Checkout Page & Skip Shop, Product, and Cart Pages
- Understanding the Impact of git reset --hard Command
Your Questions / Comments
If you found this article interesting, found errors, or just want to discuss about it, please get in touch.