Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now that you know how WordPress Themes work, it's important to also understand what templates are used for each page. This is all controlled by what's known as the WordPress Template Hierarchy and it looks like this. Every time you visit a page on a WordPress site, the application works with the database to figure out what template file will be used. The process starts on the left and ends on the right. And the first appropriate available template is selected for each page. So if you're visiting a single post, and your theme has a template file called single.PHP, that template file is used.
Here's how that process works, step by step. You visit a page and WordPress needs to know the type of page this is. The page is identified as a singular page, meaning it can be either a post or a static page. This is a post, so now we have to find out what type of post it is, either an attachment, a custom post type or a standard blog post. It's a blog post, so now WordPress looks for the single-post.php template in the theme. When it can't find single-post.php, it looks for single.php instead and if it can't find single.php either, it would default to index.php.
In fact, no matter where you go on the site, if no template is available. WordPress will always default to index.php. Knowing how to use the WordPress Template Hierarchy means you can quickly identify what template is being used for a page or post, or index on your site. It also means you can create custom templates that kick in for specific scenarios. You'll notice that for categories you can create custom template files for individual category slugs or IDs.
You can have custom single templates for custom post types. You can create various custom templates for your front page and the list goes on. As we start working with individual templates in this course, I urge you to go back and check this diagram every once in a while to figure out what's going on and which templates we're working on. And also, get a better idea how you can then take what we're doing and expand it to make custom templates for custom situations.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.