Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!