Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development Building Page Templates in WordPress The page.php File

Anthony c
Anthony c
20,907 Points

Does WordPress Know to Look for Page.php automatically?

I didn't notice that we initialized or signaled to wp that page.php would be our page template. Is core set up to look for a page.php from the get go?

2 Answers

Kevin Korte
Kevin Korte
28,149 Points

Wordpress uses this logic to decide which template to display. I used the graph about mid way down the page a lot.

https://developer.wordpress.org/themes/basics/template-hierarchy/

Anthony c
Anthony c
20,907 Points

Thanks for the additional reading, kevin.

So in this very basic case, yes wordpress is automatically looking for page.php without us telling it?

Kevin Korte
Kevin Korte
28,149 Points

It is, but it is one of the very last page templates it resorts to using.

Anthony,

In short--yes, but WP looks for a page template by using a hierarchy (the diagram Kevin Korte linked to). If you read that diagram left-to-right, starting with "Singular Page", you'll see that WP looks for several templates. page.php is the default, fall-back template if no other templates exist; and if page.php doesn't exist, WP always falls back to index.php.

That diagram is well worth getting to know--it's key to understanding template usage.