File Hierarchy in WordPress

Chris Ashman
1 min readApr 18, 2021

In WordPress, we have a file hierarchy, and this hierarchy determines the order content shows up in WordPress. It is easy to remember because it consists of three files page-{template name}.php, page.php, and index.php. Each file controls a different piece of WordPress with the index.php being the default page of content. In web development, the index file controls all the content that would appear throughout the website. In PHP, the index file does not contain content and is left blank. It is still considered the default file but is empty.

Page.php is the second default page before the index page. This file contains all the information that would be received on a page made from WordPress. The page file contains information that controls the content in WordPress. It contains a header, footer, and content loop that goes on a page. If a developer uses a page.php, it becomes the default content instead of the index file. It works similarly to the index page. The page.php file also follows the same rules as the index file.

Lastly, we have the page-{template name}.php file and these are the highest files on the page hierarchy. These files contain a template name that categorizes the content that will be shown on a page. An example of this would be creating a page-gallery.php file and assigning it to a page in WordPress. After that, the information that is assigned to that page will show up only on that page.

--

--