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 Custom Post Type Templates in WordPress The Portfolio Homepage

Andi Wilkinson
Andi Wilkinson
26,822 Points

Do you need to use a template?

I usually just fall back on the hierarchy. What is best practice? would WordPress not default automatically to use page-pagename.php without defining it as a template?

2 Answers

Andrew Shook
Andrew Shook
31,709 Points

No, WordPress would only use page-PAGENAME.php template if it existed. If it doesn't exist, it will then try to use the page.php template. If the page.php template doesn't exist it will use the index.php template file. Now if you do have a template page-PAGENAEM.php, you are not required to use the template name comment at the top of the file.

<?php
/*
Template Name: My Custom Page
*/
Andi Wilkinson
Andi Wilkinson
26,822 Points

yes but you can make page.php be called page-home etc and page-about and it will automatically default is what Im saying - this was touched on in the next video I was jumping the gun! - also I am forgetting for CPTs its the archive page it uses! - sorry - was thinking out loud a bit!