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 Creating Custom Page Templates in WordPress

Jeffrey Cunningham
Jeffrey Cunningham
5,592 Points

Naming conventions for custom templates.

In the video it is stated that naming your custom page template with a page prefix is a good idea. However, the codex states

"Alert: Important! Do not use page- as a prefix, as WordPress will interpret the file as a specialized template, meant to apply to only one page on your site."

https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/

Does it matter if I use page-blah.php for a custom template? To me it seems like this would conflict with the page-$slug.php or page-$id.php templates.

2 Answers

Kevin Korte
Kevin Korte
28,149 Points

It depends, if you want to have a global custom template that you have to manually assign a post to use that template, than do not use the page- naming convention.

If you have a custom content type, and you what to have a custom template for it, you could use page-{slug} so wordpress will pick it up automatically.

Neither is wrong, just depends on the results you want.

Jeffrey Cunningham
Jeffrey Cunningham
5,592 Points

Thanks Kevin. Sorry I should have clarified that I was referring to a global custom template situation. Now I'm trying to figure out why you do not want to use that naming convention for a custom template.

So hypothetically, If I had a global custom template named page-portfolio.php and then created a page called portfolio that receives the parmalink "/portfolio" and which, is not assigned to the template, it will ignore the fact that page-portfolio.php is a custom template and still use it to display the portfolio page content?

Kevin Korte
Kevin Korte
28,149 Points

If I’m understanding your question correctly, than yes. For a global custom template, you would want to avoid using page-{template}.php as a template name, because the page- prefix will cause wordpress to interpret the file as a specialized template meant only for one page.

With a global template, as long as it doesn’t break Wordpress’s default naming convention for templates, and you add /* Template Name: Example Template */

Than in the page attributes box on the post or page screen, you’ll have a template dropdown that you can use to select which custom template you want that post to use.

Does that help?

Here are some resources.

Kevin Korte
Kevin Korte
28,149 Points

Awesome, you're welcome!