{"id":234,"date":"2025-06-01T09:12:07","date_gmt":"2025-06-01T09:12:07","guid":{"rendered":"https:\/\/brugbarviden.dk\/?p=234"},"modified":"2025-06-01T11:42:18","modified_gmt":"2025-06-01T11:42:18","slug":"wordpress-template-hierarchy","status":"publish","type":"post","link":"https:\/\/brugbarviden.dk\/?p=234","title":{"rendered":"WordPress Template Hierarchy"},"content":{"rendered":"\n<p>WordPress Template Hierarchy<\/p>\n\n\n\n<p>Every Template in wordpress has a corresponding php file. I have added the php files that each template uses. Below is a table with further explanations for each template. <\/p>\n\n\n\n<figure class=\"wp-block-image alignwide size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"590\" src=\"https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordperss-1a-1024x590.jpg\" alt=\"\" class=\"wp-image-239\" srcset=\"https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordperss-1a-1024x590.jpg 1024w, https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordperss-1a-300x173.jpg 300w, https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordperss-1a-768x443.jpg 768w, https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordperss-1a-1536x885.jpg 1536w, https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordperss-1a.jpg 1574w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image alignwide size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"759\" height=\"844\" src=\"https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordpress-1b.jpg\" alt=\"\" class=\"wp-image-240\" srcset=\"https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordpress-1b.jpg 759w, https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordpress-1b-270x300.jpg 270w\" sizes=\"auto, (max-width: 759px) 100vw, 759px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-table alignwide\"><table class=\"has-contrast-color has-text-color has-link-color has-fixed-layout\"><tbody><tr><td><strong>WP Template Name<\/strong><\/td><td><strong>Corresponding php file<\/strong><\/td><td><strong>Description of php file.<\/strong><\/td><\/tr><tr><td><strong>All archives\u00a0<\/strong><\/td><td><strong><code>archive.php<\/code><\/strong><\/td><td>IIf you do not have a <strong>category<\/strong>&#8211;<strong>specific<\/strong> <strong>template (category.php) <\/strong>or <strong>tag-specific template (tag.php)<\/strong>, WordPress will fall back to the general archive template:<strong> archive.php.<\/strong><br><strong>Example\u00a0You have a navigation menu with 3 categories:ProteinsDietFats<\/strong><br>When a user clicks on any of these, WordPress loads the corresponding category archive page. If there is:No category-{slug}.phpNo category.php Then WordPress will use:<strong>archive.php<\/strong><\/td><\/tr><tr><td><strong>Author archives<\/strong><\/td><td><strong>author.php<\/strong><\/td><td><\/td><\/tr><tr><td><strong>Category archives<\/strong><\/td><td><strong>Category.php<\/strong><br><br>The hierarchy for Categories: <br><br>.1) <code>category-{slug}.php<\/code> e.g.,<code> category-news.php<\/code><br><br>2)category-{id}.php e.g., category7.php<br><br><strong>3)Category.php<br>4) Archive.php<br>5) index.php<\/strong><\/td><td><\/td><\/tr><tr><td>Date archives<\/td><td>date.php<\/td><td><\/td><\/tr><tr><td>Tag Archives<\/td><td>tag.php<\/td><td><\/td><\/tr><tr><td>Blog home<\/td><td>1. If your homepage display is set to <strong>Static page as homepage <\/strong>+ <strong>post page <\/strong>is set as homepage + post\u00a0<br><br><strong>1)Home.php\u00a0<br>2)\u00a0index.php\u00a0<\/strong><br><br>2. If your homepage displays is set to <strong>\u201cA static page\u201d:<\/strong>Homepage (the page set as \u201cHomepage\u201d):<br><br><strong>1) front-page.php \u2192 if it exists <br>2) else<br> page-{slug}.php or page-{id}.php<br>3) else page.php<br>4) else index.php<\/strong><br><\/td><td><strong>Home.php <\/strong>is used for the <strong>homepage <\/strong>if<strong> front-page.php<\/strong> and if your reading-settings are set to&nbsp; <strong>latest posts&nbsp;<\/strong><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXc3TM0ta2DHuXOoK2inNqepAG2syOCjK-1xBRiET2KSl7r-3Drmv10oaIfV4C3bDpg28Eh1-CadAL-9OwXIDilv-XHhk9owtmOyAr8sLyHNOLMEreMrrcgUuhttvj31wNWDvjW1uw?key=TaNsc3dOwrVRfiwPmHpNBA\" width=\"306\" height=\"140\"><br>Or if your reading settings are set to \u201c<strong>A static page\u201d<\/strong> +<strong> \u201cposts page\u201d&nbsp;<\/strong><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXc31iPkJfe1mOcaSYYMs4gYLre5WV0nifaaa6rx-2nVnE3E4Ed87jDu28SZrYXpdXSfXAkhOFzqE3LNKKOf9zcH0dexRLkNp3mHclJ277nCaX9_4AKKcBcCpgqJPnUx0I4XHp1X1w?key=TaNsc3dOwrVRfiwPmHpNBA\" width=\"306\" height=\"143\"><\/td><\/tr><tr><td><strong>Front Page<\/strong><\/td><td><strong>front-page.php<\/strong><\/td><td><strong>front-page.php <\/strong>is only used if a <strong>static homepage <\/strong>is selected. It is never used when &#8220;Your latest posts&#8221; is selected.It\u2019s never used for normal pages that are not a static homepage.&nbsp;<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXfWoBUhjbBxLLZun6pmEN5UENn136MG1mjz3WVLQeReWzyD8f4GSeDzVhX3LOYoVjlOVfTf1RwZJMMdbXqHDE4PCtFPJ4-ANv8EA_4TSfkWybRp65Do2u6DgPbS6U4EkD69GIYkWg?key=TaNsc3dOwrVRfiwPmHpNBA\" width=\"242\" height=\"107\"><\/td><\/tr><tr><td><strong>Pages&nbsp;<\/strong><\/td><td><strong>For a normal page that is not set to static homepage: this is the hierarchy\u00a0<\/strong><br><strong>1)Page-{slug}.php<br>2) Page-{id}.php<br>3)Page.php<br>4)index.php<br><\/strong><br><strong>Template hierarchy: if a page is set to a static page + home page. This is the hierarchy<\/strong><br><br>1)Front-page.php<br>2)page-{slug}.php<br> (e.g., page-home.php)<br>3) Page-{id}.php<br>4) page.php<br>5) Index.php<br><br>If a homepage is set to show your latest posts wordpress does not treat it as a page and this will be the hierarchy\u00a0\u00a0\u00a0<br>1) Home.php<br>2) index.php<\/td><td>Used for all wordpress <strong>pages.<\/strong><br><strong>If the Page is set as a static Homepage, then front-page.php gets top priority.<\/strong><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXfWoBUhjbBxLLZun6pmEN5UENn136MG1mjz3WVLQeReWzyD8f4GSeDzVhX3LOYoVjlOVfTf1RwZJMMdbXqHDE4PCtFPJ4-ANv8EA_4TSfkWybRp65Do2u6DgPbS6U4EkD69GIYkWg?key=TaNsc3dOwrVRfiwPmHpNBA\" width=\"242\" height=\"107\"><br><strong>If it&#8217;s just a normal Page (not the homepage), front-page.php is ignored.<\/strong><br><strong>If the Page is set as a static Homepage but no front-page.php exists then the homepage is likely rendered by page.php&nbsp;<\/strong><br><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXfWoBUhjbBxLLZun6pmEN5UENn136MG1mjz3WVLQeReWzyD8f4GSeDzVhX3LOYoVjlOVfTf1RwZJMMdbXqHDE4PCtFPJ4-ANv8EA_4TSfkWybRp65Do2u6DgPbS6U4EkD69GIYkWg?key=TaNsc3dOwrVRfiwPmHpNBA\" width=\"242\" height=\"107\">&nbsp;<\/td><\/tr><tr><td>Pages no title<\/td><td>page.php<\/td><td><\/td><\/tr><tr><td>index.php<\/td><td>index.php<\/td><td>If no php files exist for all the other templates (page.php, home.php , archive.php etc) they all default to index.php and the wordpress post, page, archive page etc will all display content based on what index.php tells it to do.&nbsp;<\/td><\/tr><tr><td>search<\/td><td>search.php<\/td><td><\/td><\/tr><tr><td>Single Post<\/td><td>Single.php<br><br><br>Single post hierarchy <br><br>1) \u00a0<strong>Single-post-{slug}.php <\/strong>e.g., <br>single-post-how-to-code.php <br>(\u2757Rarely used \u2014 must be created manually)<br><br>2) <strong>Single-post.php <\/strong>Template for all single post entries (not pages or CPTs)<br><br>3) <strong>Single.php <\/strong><br>General fallback for any single post or custom post type<br><br>4) <strong>Singular.php<\/strong><br><strong> <\/strong>General fallback for all singular content (posts, pages, CPTs)<br><br><strong>5) index.php <\/strong>Final fallback<\/td><td>This is used for each of your <strong>posts<\/strong>. When you click a <strong>post <\/strong>it uses the <strong>Single posts template.<\/strong><\/td><\/tr><tr><td>Single item: post<\/td><td>Single-post.php&nbsp;Single.php&nbsp;<\/td><td><\/td><\/tr><tr><td>Page: 404<\/td><td>404.php&nbsp;<\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>WordPress Template Hierarchy Every Template in wordpress has a corresponding php file. I have added the php files that each template uses. Below is a table with further explanations for each template. WP Template Name Corresponding php file Description of php file. All archives\u00a0 archive.php IIf you do not have a category&#8211;specific template (category.php) or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":243,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,1,24,25],"tags":[],"class_list":["post-234","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it","category-uncategorized","category-webdevelopment","category-wordpress"],"jetpack_featured_media_url":"https:\/\/brugbarviden.dk\/wp-content\/uploads\/2025\/06\/wordpress-template-hierarchy.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=\/wp\/v2\/posts\/234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=234"}],"version-history":[{"count":7,"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions\/252"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=\/wp\/v2\/media\/243"}],"wp:attachment":[{"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brugbarviden.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}