Template Hierarchy

Learn about the order in which WordPress uses different theme files to render a page on screen.

WordPress uses a template hierarchy which decides which file is used to display a given page. It defines the order in which the file is chosen.

Every page that WordPress shows comes from a template file. The hierarchy decides which file will be used. It has a series of fallback options in case a file is not available. All these fallback options end with index.php which is a necessary file for all themes. Theoretically speaking, only an index.php file can be used to create a fully functional theme. However, for the sake of customization, a theme contains different files that power different types of pages (home, blog, search, etc.) or different sections of a page (header, footer, sidebar, etc).

The WordPress codex shows a visual overview of the template hierarchy. We will break down this hierarchy according to page types so it is easy to understand. There are seven main types of pages in a website. Even though these types of pages have a separate hierarchy, they also share some files like header.php and footer.php.

Front page

The home page is the landing page of any website. To display this page, WordPress looks for files in the following order:

Get hands-on with 1200+ tech skills courses.