{"id":10384,"date":"2020-08-09T15:00:13","date_gmt":"2020-08-09T13:00:13","guid":{"rendered":"https:\/\/qodeinteractive.com\/magazine\/?p=10384"},"modified":"2021-03-04T17:37:20","modified_gmt":"2021-03-04T16:37:20","slug":"wordpress-template-hierarchy","status":"publish","type":"post","link":"https:\/\/qodeinteractive.com\/magazine\/wordpress-template-hierarchy\/","title":{"rendered":"Understanding the WordPress Template Hierarchy"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]For every customizable product, there needs to be a very complex system in place in order to provide a high level of customization. This is also the case with website creation. WordPress has approached this problem with an ultimately elegant solution\u2014theme template files. These files are used to determine what kind of page and which parts would be presented. Since there are large numbers of variations to these files, made even larger by custom WordPress themes, it is integral to have a way to sift through them all to find the appropriate one for the page you are looking at. This is what the Template Hierarchy is for.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]In this article we\u2019ll cover the following topics:[\/vc_column_text][vc_empty_space height=&#8221;22px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#template-file-system\">Introduction to the Template File System<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#explanation\">The Template Hierarchy Explained<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#template-hierarchy-in-code\">The Template Hierarchy in Code<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;70px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"template-file-system\"><\/a>Introduction to the Template File System in WordPress<\/h2>\n<p>[\/vc_column_text][vc_column_text]With a static webpage, you only need to use HTML and CSS to create it. The former provides the layout and the latter the style of the page. WordPress, on the other hand, uses PHP to incorporate these and many other resources in order to present a page. This lets <strong>WordPress provide its users with the options to customize parts of pages, which is one of the reasons it has gained immense popularity<\/strong>. This <strong>customization is possible thanks to different PHP files<\/strong> that are used to determine how each aspect of your page appears. These files are called <em><strong>Template Files<\/strong><\/em>.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]For example, pages in WordPress are mostly composed of a header, content, sidebar, and a footer. All of these elements are rendered using the header.php, content.php, sidebar.php, and footer.php template files. Although the composition of a page may vary all of those variations need to be defined within their respective template files. This is the case with custom themes, for instance. The files contain information on what a particular part of a page should look like, how it should render, and what parts it should include.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]This method of rendering pages used by WordPress might seem complex initially, however, it is quite efficient. <strong>The modular approach to templates enables users to make changes to a single file and apply that wherever they like throughout the website.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]It is important to note that there are several predetermined template files that WordPress uses, those are:[\/vc_column_text][vc_empty_space height=&#8221;23px&#8221;]<ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">index.php<\/span>\n            <\/span><span class=\"qodef-ul-mark\">: <\/span><span class=\"qodef-ul-title-content\">This is the main template file. It and the style.css are required for every theme.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">style.css<\/span>\n            <\/span><span class=\"qodef-ul-mark\">: <\/span><span class=\"qodef-ul-title-content\">This is the main stylesheet. As stated above, it is required for any theme. It also contains the header comment section with information about your theme.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">home.php<\/span>\n            <\/span><span class=\"qodef-ul-mark\">: <\/span><span class=\"qodef-ul-title-content\">The home page template file is called for the front page by default. If you do not set a static front page, this template is used to show the latest posts.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">header.php<\/span>\n            <\/span><span class=\"qodef-ul-mark\">: <\/span><span class=\"qodef-ul-title-content\">This template file usually contains your site\u2019s document type, meta information, links to stylesheets and scripts, and other relevant data.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">single.php<\/span>\n            <\/span><span class=\"qodef-ul-mark\">: <\/span><span class=\"qodef-ul-title-content\">The single post template is used to present a single post on a webpage.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">page.php<\/span>\n            <\/span><span class=\"qodef-ul-mark\">: <\/span><span class=\"qodef-ul-title-content\">This template is used when visitors request individual pages, and it can apply to a single page, a page section, or a group of pages determined by class.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">archive.php<\/span>\n            <\/span><span class=\"qodef-ul-mark\">: <\/span><span class=\"qodef-ul-title-content\">The archive template is used to present posts by category, author, or date.\nNote: this template will be overridden if the following templates are present: category.php, author.php, or date.php.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">search.php<\/span>\n            <\/span><span class=\"qodef-ul-mark\">: <\/span><span class=\"qodef-ul-title-content\">The search results template is used to display a user\u2019s search results.<\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_column_text]Along with these there are also many other less common or less necessary template files like: <strong>date.php, rtl.css, category.php, tag.php, taxonomy.php, author.php, comments.php, singular.php, front-page.php, page-{slug}.php, single-{post-type}.php, archive-{post-type}.php, attachment.php<\/strong><br \/>\n<strong>image.php, 404.php<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Given all of these files as well as those added by custom themes, WordPress needed to find a way to navigate through them efficiently. The method that WordPress implemented to do that is the Template Hierarchy.[\/vc_column_text][vc_empty_space height=&#8221;72px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"explanation\"><\/a>The WordPress Template Hierarchy Explained<\/h2>\n<p>[\/vc_column_text][vc_column_text]In order to have comprehensive customization available for users while remaining fast, efficient, and reliable, WordPress implemented a hierarchy for all those template files. <strong>Template Hierarchy is how WordPress searches for the proper template files to use once a page has been requested by a user<\/strong>. Namely, once a user clicks on a link to a certain page, WordPress uses the query string from that link to search for template files it needs to render that page. In order for that search to be as smooth and fast as possible WordPress has predefined the hierarchy of template files. This, in turn, sets the path which will be used to search for the proper template to use.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The following is a representation and explanation of the full Template Hierarchy implemented by WordPress for a number of query types:<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;72px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Home Page Display<\/h3>\n<p>[\/vc_column_text][vc_column_text]<strong>By default, the home page is set to display your latest blog posts. This page is called the Blog Posts Index and can be set by navigating to Settings &gt; Reading.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/08\/Reading-Settings.jpg\" class=\"attachment-full size-full\" alt=\"Reading Settings\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/08\/Reading-Settings.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/08\/Reading-Settings-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/08\/Reading-Settings-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]The home.php template file is used to render the blog posts index, whether used for the front page or any other page of the website. If the home.php file does not exist, WordPress will then use the index.php file to render the page.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]So the template hierarchy would go like this:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">home.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_column_text]<strong>Note:<\/strong> If the front-page.php template file exists, it will override the home.php template.[\/vc_column_text][vc_empty_space height=&#8221;72px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Front Page Display<\/h3>\n<p>[\/vc_column_text][vc_column_text]The front-page.php template file, as the name suggests, is used to render your site\u2019s front page. It is used regardless if <em>Your homepage displays<\/em> option is set to the <em>Blog Posts Index<\/em> or to a static page. If the front-page.php file does not exist, WordPress will either use the home.php or page.php template files depending on the setup in <em>Settings &gt; Reading<\/em>. If neither of those files exists, it will use the index.php file. Therefore the template hierarchy would go like this:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">front-page.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">Used for both available options within Settings &gt; Reading.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">home.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the front-page.php file is not available and \u201cyour latest posts\u201d is chosen in \u201cYour homepage displays\u201d, WordPress will look for the home.php template file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">When a specific \u201cHomepage\u201d is selected in the \u201cYour homepage displays\u201d section, then the page.php file will be next if the front-page.php file has not been found.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">When \u201cYour homepage displays\u201d settings are used but the associated files are not found, WordPress uses the index.php template file as the absolute fallback.<\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Privacy Policy Page Display<\/h3>\n<p>[\/vc_column_text][vc_column_text]<strong>The privacy-policy.php template file<\/strong> ( Which was added in the WordPress version 4.9.6 as an editable template) is used to<strong> render your site\u2019s Privacy Policy page<\/strong>. It takes precedence over the page.php template file. If the privacy-policy.php file does not exist, WordPress will either use the page.php or singular.php files depending on the available templates. If neither of those files exists, it will use the index.php file. Therefore the template hierarchy would go like this:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">privacy-policy.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">(From WordPress version 4.9.6 onward) Used for the Privacy Policy page set in the Change your Privacy Policy page section within Settings &gt; Privacy.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">A custom template file<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">The page template assigned to the Privacy Policy page using the get_page_templates() function.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page-privacy.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page-{id}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If, for example, the page ID is 61 WordPress will look to use the page-61.php file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">6.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">singular.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">7.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Single Post<\/h3>\n<p>[\/vc_column_text][vc_column_text]The single post template file is <strong>used to render a single post<\/strong>. For this purpose WordPress uses the following path structure:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single-{post-type}-{slug}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">(From WordPress version 4.4 onward) First, WordPress looks for a template of the specific post. For example, if the post type is \u201cblog\u201d and the post slug is \u201cnews\u201d, WordPress will look for single-blog-news.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single-{post-type}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the single-{post-type}-{slug}.php file is not found and the post type is \u201cblog\u201d, WordPress will look for the single-blog.php template file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If neither of the previous two files could be found, WordPress then falls back to single.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">singular.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">After which it falls back to singular.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">Finally, as we saw earlier, WordPress ultimately falls back to the index.php file if there is no other viable option.<\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\"><a id=\"single-page\"><\/a>Single Page<\/h3>\n<p>[\/vc_column_text][vc_column_text]This is the <strong>template file used to render a static page<\/strong> (page post-type). Note that unlike other post-types, the page post-type is specific in WordPress and uses the following path:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">A custom template file<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">The page template assigned to the page using a get_page_templates() function.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page-{slug}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If there is no custom template file and the page slug is, for example, recent-news, WordPress will search for the page-recent-news.php file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page-{id}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If, for example, the page ID is 61, WordPress will look to use the page-61.php template file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">singular.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">6.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Category<\/h3>\n<p>[\/vc_column_text][vc_column_text]In order to render category archive index pages WordPress uses the following path:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">category-{slug}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the category\u2019s slug is \u201cnews\u201d, WordPress will look for category-news.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">category-{id}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the category-{slug}.php file was not found and the category\u2019s ID is, for example, 61 WordPress will look for the category-61.php template file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">category.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">archive.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Tag<\/h3>\n<p>[\/vc_column_text][vc_column_text]To display a tag archive index page, WordPress uses the following path:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">tag-{slug}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the tag\u2019s slug is \u201cbreaking\u201d, WordPress will look for tag-breaking.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">tag-{id}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the tag-{slug}.php was not found and the tag\u2019s ID is 61, WordPress will look for tag-61.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">tag.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">archive.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[\/vc_column][\/vc_row][vc_row][vc_column][vc_empty_space height=&#8221;44px&#8221;][vc_widget_sidebar sidebar_id=&#8221;new-top-picks-banner&#8221;][vc_empty_space height=&#8221;84px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Custom Taxonomies<\/h3>\n<p>[\/vc_column_text][vc_column_text]For custom taxonomies WordPress uses a slightly different template file path:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">taxonomy-{taxonomy}-{term}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the taxonomy is sometax, and the taxonomy\u2019s term is someterm, WordPress will look for taxonomy-sometax-someterm.php. In the case of post formats, the taxonomy is \u2018post_format\u2019 and the terms are \u2018post-format-{format}. For example, the link post format would be taxonomy-post_format-post-format-link.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">taxonomy-{taxonomy}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If searching for taxonomy-{taxonomy}-{term}.php did not yield any results and the taxonomy is sometax, WordPress will look for the taxonomy-sometax.php file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">taxonomy.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">archive.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Custom Post Types<\/h3>\n<p>[\/vc_column_text][vc_column_text]Custom post types use the following path to render the appropriate archive index page.[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">archive-{post_type}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the post type is \u201cblog\u201d, WordPress will look for the archive-blog.php template file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">archive.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_column_text]In order to render a single post type template, WordPress uses the single post display path laid out above.[\/vc_column_text][vc_empty_space height=&#8221;72px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Author Display<\/h3>\n<p>[\/vc_column_text][vc_column_text]You might have noticed by now that a pattern emerges as you go through these path explanations. And rendering the author display follows that same pattern:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">author-{nicename}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the author\u2019s nicename is \u201cClint\u201d, WordPress will look for author-clint.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">author-{id}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the author\u2019s ID is 61, WordPress will look for the author-61.php file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">author.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">archive.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Date<\/h3>\n<p>[\/vc_column_text][vc_column_text]Rendering archive index pages that are date-based (used to display posts by date\/time) follows the structure outlined below:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">date.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">archive.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Search Result<\/h3>\n<p>[\/vc_column_text][vc_column_text]The search results template, which serves to display visitors\u2019 search results, follows the structure outlined below:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">search.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">404 (Not Found)<\/h3>\n<p>[\/vc_column_text][vc_column_text]Likewise, the 404 template file that displays when WordPress isn\u2019t able to locate a post, page, or some other content, is called in the following order:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">404.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Attachment<\/h3>\n<p>[\/vc_column_text][vc_column_text]Calling an attachment page (attachment post-type), which displays attachments such as images or other files, follows the path outlined below:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">{MIMEtype}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">This can be any MIME type (Multipurpose Internet Mail Extensions; can refer to files such as image.php, video.php, pdf.php). For plain or text types, the path below is used in the following order:<\/span>        <\/div>\n        <div class=\"qodef-ol-items\">\n\t\t            <div class=\"qodef-ol-item\">\n                <span class=\"qodef-ol-item-number\">1.1<\/span>\n\t\t\t\t<span class=\"qodef-ol-item-text\">text-plain.php<\/span>\n\t\t\t\t            <\/div>\n\t\t\t            <div class=\"qodef-ol-item\">\n                <span class=\"qodef-ol-item-number\">1.2<\/span>\n\t\t\t\t<span class=\"qodef-ol-item-text\">plain.php<\/span>\n\t\t\t\t            <\/div>\n\t\t\t            <div class=\"qodef-ol-item\">\n                <span class=\"qodef-ol-item-number\">1.3<\/span>\n\t\t\t\t<span class=\"qodef-ol-item-text\">text.php<\/span>\n\t\t\t\t            <\/div>\n\t\t\t    <\/div>\n<\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">attachment.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single-attachment-{slug}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">For example, if the attachment slug is \u201cbirthday\u201d then WordPress will search for the single-attachment-birthday.php file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single-attachment.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">6.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">singular.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">7.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Embeds<\/h3>\n<p>[\/vc_column_text][vc_column_text]To render a post that is embedded in WordPress, the embed template file is called. WordPress version 4.5 and newer use the path outlined below:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">embed-{post-type}-{post_format}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">WordPress first searches for the specific post template. For example, if the post type is \u201cpost\u201d and the format is \u201caudio\u201d, WordPress will look for embed-post-audio.php.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">embed-{post-type}.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the post type is \u201cpost\u201d and WordPress doesn\u2019t locate the specific post template, it will next look for the embed-post.php file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">embed.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">If the first two aren\u2019t found, WordPress will then look for the embed.php template file.<\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">wp-includes\/theme-compat\/embed.php<\/span>\n            <\/span><span class=\"qodef-ol-mark\">:<\/span> <span class=\"qodef-ol-title-content\">Finally, if it fails to locate any of the previous files, WordPress will call on the wp-includes\/theme-compat\/embed.php template.<\/span>        <\/div>\n    <\/div>[vc_empty_space height=&#8221;33px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Handling Non-ASCII Characters<\/h3>\n<p>[\/vc_column_text][vc_column_text]Using both un-encoded and encoded forms for names was introduced in WordPress version 4.7. If any dynamic part of a template name has non-ASCII characters in its name, users can choose between the un-encoded and encoded form.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]For example, the page template hierarchy would look like this for a page with the name \u201cHello World \ud83d\udcaf\u201d and an ID that is 61:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page-hello-world-\ud83d\udcaf.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page-hello-world-%F0%9F%92%AF.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page-61.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">page.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">singular.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_column_text]The same structure and behavior will apply to term names, author nicenames, and post slugs as well.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]You could test this out and look further into the Template Hierarchy by using either the <a href=\"https:\/\/wordpress.org\/plugins\/show-current-template\/\" target=\"_blank\" rel=\"noopener noreferrer\">Show Current Template<\/a> or <a href=\"https:\/\/wordpress.org\/plugins\/which-template\/\" target=\"_blank\" rel=\"noopener noreferrer\">Which Template<\/a> plugins on whichever WordPress theme you\u2019re using. These plugins allow you to see exactly which template files are used on any page of your website. The Show Current Template plugin, for example, allows you to <strong>click on the <em>Template<\/em> option in the admin bar on a page<\/strong>. This, in turn, will open a drop-down containing the full list of the template files being used.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/08\/Handling-Non-ASCII-Characters.jpg\" class=\"attachment-full size-full\" alt=\"Handling Non ASCII Characters\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/08\/Handling-Non-ASCII-Characters.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/08\/Handling-Non-ASCII-Characters-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/08\/Handling-Non-ASCII-Characters-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;82px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">The Template Hierarchy Simplified<\/h3>\n<p>[\/vc_column_text][vc_column_text]In the simplest terms, the Template Hierarchy is a predefined order which WordPress follows in order to find appropriate files with which to build a page. It is essentially a blueprint for WordPress and theme developers to follow so that themes are structured properly and can be interpreted correctly. To illustrate this, we will use a simplified version of one of the examples above.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To display a single post template, which renders a page that shows a single post, there is a chain of <strong>five possible files that can be used<\/strong>. Say a user is on a blog list page of a website and sees an interesting article snippet. If they click on its link to read further, multiple things that happen from this point on within WordPress. The process of opening that single post starts with WordPress taking the relevant post information from the query string within the clicked link. Let\u2019s say that the link was for a just-published blog post with a breaking news article. WordPress would take the post type and slug, in this case, \u201cblog\u201d and \u201cbreaking\u201d, and would start the search for the template files.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]First, it searches for a template file of the specific post that was accessed. This means that it will use the post\u2019s type and slug to search for the single-{post-type}-{slug}.php file. That would be the single-blog-breaking.php template file.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]If that file does not exist it will search for the simpler, less specific version, which would be the single-blog.php template file.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Then, if both the first and second file could not be found, WordPress would look for the single.php template file. This is a more common file found in most themes.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]However, if for some reason the single.php file is not found, WordPress will then search for the singular.php template file.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Finally, if no other file is available WordPress will default to the index.php template file.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]So the full Template Hierarchy for the single post template would look like this:[\/vc_column_text][vc_empty_space height=&#8221;38px&#8221;]<div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">1.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single-{post-type}-{slug}.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">2.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single-{post-type}.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">3.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">single.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">4.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">singular.php<\/span>\n            <\/span>        <\/div>\n    <\/div><div class=\"qodef-ordered-list-item \">\n\t        <div class=\"qodef-ol-title-holder\">\n            <span class=\"qodef-ol-title-number\">5.<\/span>\n                        <span class=\"qodef-ol-title\">\n                <span class=\"qodef-ol-title-text\">index.php<\/span>\n            <\/span>        <\/div>\n    <\/div>[vc_column_text]You may have noticed that each of the hierarchies laid out above ends with the index.php file. This is a measure WordPress has taken in order to ensure that there is always a file it can use to render a page. This is also one of the main reasons why you cannot activate a theme that does not have an index.php file within it.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"template-hierarchy-in-code\"><\/a>The WordPress Template Hierarchy in Code<\/h2>\n<p>[\/vc_column_text][vc_column_text]Now that we have seen what the Template Hierarchy is in general, let us delve into the code that forms it. We mentioned in the previous paragraph that one of the main reasons <strong>WordPress does not allow activation of a theme is that the index.php file is missing<\/strong>. The other major reason is more technical in nature\u2014most requests to a WordPress website go through the index.php file. It contains the following lines of code:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\n\/**\r\n* Front to the WordPress application. This file doesn't do anything, but loads\r\n* wp-blog-header.php which does and tells WordPress to load the theme.\r\n*\r\n* @package WordPress\r\n*\/\r\n\/**\r\n* Tells WordPress to load the WordPress theme and output it.\r\n*\r\n* @var bool\r\n*\/\r\ndefine( 'WP_USE_THEMES', true );\r\n\/** Loads the WordPress Environment and Template *\/\r\nrequire( dirname( __FILE__ ) . '\/wp-blog-header.php' );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]The final line of code above is what pulls in the wp-blog-header.php file. This file, in turn, contains the following lines:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if ( !isset($wp_did_header) ) {\r\n$wp_did_header = true;\r\nrequire_once( dirname(__FILE__) . '\/wp-load.php' );\r\nwp();\r\nrequire_once( ABSPATH . WPINC . '\/template-loader.php' );\r\n}<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]Now, for our purposes, the interesting line here is:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">require_once( ABSPATH . WPINC . '\/template-loader.php' );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]This line loads the template-loader.php file. This is the file that contains the template hierarchy. And that core part that defines the template hierarchy is:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if ( wp_using_themes() ) {\r\n$tag_templates = array(\r\n'Is_embed' =&gt; 'get_embed_template',\r\n'is_404' =&gt; 'get_404_template',\r\n'is_search' =&gt; 'get_search_template',\r\n'Is_front_page' =&gt; 'get_front_page_template',\r\n'is_home' =&gt; 'get_home_template',\r\n'is_privacy_policy' =&gt; 'get_privacy_policy_template',\r\n'is_post_type_archive' =&gt; 'get_post_type_archive_template',\r\n'is_tax' =&gt; 'get_taxonomy_template',\r\n'is_attachment' =&gt; 'get_attachment_template',\r\n'is_single' =&gt; 'get_single_template',\r\n'is_page' =&gt; 'get_page_template',\r\n'is_singular' =&gt; 'get_singular_template',\r\n'is_category' =&gt; 'get_category_template',\r\n'is_tag' =&gt; 'get_tag_template',\r\n'is_author' =&gt; 'get_author_template',\r\n'is_date' =&gt; 'get_date_template',\r\n'is_archive' =&gt; 'get_archive_template',\r\n);\r\n$template = false;\r\n\/\/ Loop through each of the template conditionals, and find the appropriate template file.\r\nforeach ( $tag_templates as $tag =&gt; $template_getter ) {\r\nif ( call_user_func( $tag ) ) {\r\n$template = call_user_func( $template_getter );\r\n}\r\nif ( $template ) {\r\nif ( 'is_attachment' === $tag ) {\r\nremove_filter( 'the_content', 'prepend_attachment' );\r\n}\r\nbreak;\r\n}\r\n}\r\nif ( ! $template ) {\r\n$template = get_index_template();\r\n}\r\n\/**\r\n* Filters the path of the current template before including it.\r\n*\r\n* @since 3.0.0\r\n*\r\n* @param string $template The path of the template to include.\r\n*\/\r\n$template = apply_filters( 'template_include', $template );\r\nif ( $template ) {\r\ninclude( $template );\r\n} elseif ( current_user_can( 'switch_themes' ) ) {\r\n$theme = wp_get_theme();\r\nif ( $theme-&gt;errors() ) {\r\nwp_die( $theme-&gt;errors() );\r\n}\r\n}\r\nreturn;\r\n}<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]The first part of the code is a simple array, called <em>$tag_templates<\/em>, that consists of all possible template files. The second part has somewhat changed throughout the years. It used to be a large but simple if-else statement. However, the latest version consists of a for-loop that iterates through all of the <em>$tag_templates<\/em> array items. Each iteration checks whether that particular array item has been populated previously or not. This way it exhausts possibilities within the hierarchy so that it can later filter these and find the appropriate file to use.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]For such a crucial element of the inner workings of WordPress, this is a rather simple and elegant solution. It doesn\u2019t pose problems to either WordPress or theme developers and most of the time regular users don\u2019t even need to learn of it. All of this means that it has fulfilled its purpose flawlessly.[\/vc_column_text][vc_empty_space height=&#8221;79px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">Final Thoughts<\/h2>\n<p>[\/vc_column_text][vc_column_text]We hope that this tutorial has helped you come to grips with the concept of Template Hierarchy and how it works. Whether you are a beginner or a more knowledgeable WordPress user, we are sure that this information will come in handy for any custom work that you wish to get done. Make sure to keep the article handy as it is a great cheat-sheet to all of the hierarchies proposed by WordPress.[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Get a peek at WordPress behind the scenes with this comprehensive explanation of how the WordPress template hierarchy works and what it&#8217;s for.<\/p>\n","protected":false},"author":278,"featured_media":10398,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[14,13],"class_list":["post-10384","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-resources","tag-core","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/10384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/users\/278"}],"replies":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/comments?post=10384"}],"version-history":[{"count":0,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/10384\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media\/10398"}],"wp:attachment":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media?parent=10384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/categories?post=10384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/tags?post=10384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}