Hierarchy
Front Page
- front-page.php
if front page is a static page -> move to the Page hierarchy from here.
else,
- home.php
- index.php
Single Post Type (except page)
- Attachment Post Type
– {mimetype}-{subtype}.php -> image-jpeg.php
– image.php
– attachment.php
– will go to Custom Post - Custom Post
– single-{posttype}-{post_slug}.php
– single-{posttype}.php - Blog Post
– single-post.php
After the following behaviour, it will fallback to
- single.php
- singular.php
- index.php
Page
- { Post Template }
- page-{slug}.php
- page-{id}.php
- page.php
- singular.php
- index.php
Blog posts
- home.php
- index.php
Error page
- 404.php
- index.php
Search
- search.php
- index.php
Archives
- Author Archive
– author-{nicename}.php
– author-{id}.php
– author.php
– archive.php
– index.php - Category Archive
– category-{slug}.php
– category-{id}.php
– category.php
– archive.php
– index.php - Custom Post Type archive
– archive-{posttype}.php
– archive.php
– index.php - Custom Taxonomy Archive
– taxonomy-{taxonomy}-{term}.php
– taxonomy-{taxonomy}.php
– taxonomy.php
– archive.php
– index.php - Date archive
Embeds
The embed template file is used to render a post which is being embedded. Since 4.5, WordPress uses the following path:
embed-{post-type}-{post_format}.php– First, WordPress looks for a template for the specific post. For example, if its post type ispostand it has the audio format, WordPress would look forembed-post-audio.php.embed-{post-type}.php– If the post type isproduct, WordPress would look forembed-product.php.embed.php– WordPress then falls back to embed.php.- Finally, WordPress ultimately falls back to its own
wp-includes/theme-compat/embed.phptemplate.
Non-ASCII Character Handling
Since WordPress 4.7, any dynamic part of a template name which includes non-ASCII characters in its name actually supports both the un-encoded and the encoded form, in that order. You can choose which to use.
Here’s the page template hierarchy for a page named “Hello World ” with an ID of 6:
page-hello-world-{emoji}.phppage-hello-world-%f0%9f%98%80.phppage-6.phppage.phpsingular.php
is_single() vs is_singular()
is_single() -> this would not work for page post-type
is_singular() -> this would also work for page post-type
They tell us if the current query object has a single result and we are displaying a single item.
