If you’re yet to familiarise yourself with template hierarchy, it could be worth taking a look at this brief introduction. Whether you’re planning to build your own theme or utilising a child theme to make changes to a third party theme, it’s essential to become acquainted with the workings of template hierarchy.
This software is actually really impressive, a smart system used by WordPress to select the correct template for varying types of content. But as with anything seemingly complex, this can be challenging to navigate for the novice. This guide simplifies the process and gives a general understanding of this developer term.
Understanding template hierarchy
Whenever content is created in WordPress – a post, image, header and so on – this information is stored in a database. Whenever a visitor to your site wants to access this information, it is then displayed in the form of templates. Put simply, any theme of WordPress is just a collection of these templates including CSS and PHP files.
When WordPress reads the files in a theme it is essentially utilising this data to render the page in a complete and correct order. As such WordPress themes dictate how your content is displayed. While you may be able to change the way content is displayed by altering the theme, the actual content will stay the same.
When looking at any WordPress site, you’re actually looking at multiple templates files to create one compete page. As an example, when viewing the home page of a blog, you’ll most likely be viewing a header crated by a header.php template followed by content created by index.php, sidebar created by sidebar.php and so on.
Click on another page and you’d see those same templates but the additional content would be created by single.php instead. Being able to view this content in its correct order is only possible thanks to template hierarchy. WordPress uses this information to make the correct call on how to load your site.
One of the main default WordPress themes ‘Twenty Fifteen’ holds more than 15 template files in its theme folder. By utilising the Query String data shown on each link of your web page, WordPress determines which set of templates are used to load the page. That type of page can range from search to category pages, a home page or contact us. Once WordPress recognises the type of page it is, it can then use the template hierarchy to generate the content.
Become acquainted with template hierarchy
There’s plenty more to WordPress template hierarchy but this brief understanding should give you an idea of the system and how it works. While it can be complex, an in-depth understanding provides some great benefits including the chance to create your own theme template files.
It’s worth doing some more homework or enlisting the help of a trained developer to guide you through this system. Not only will you learn more about the workings behind your site, but you’ll have the freedom to tailor make themes.