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 trialJeffrey Cunningham
5,592 PointsNaming 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
28,149 PointsIt 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.
Kevin Korte
28,149 PointsIf 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.
Jeffrey Cunningham
5,592 PointsYes, thank you very much.
Kevin Korte
28,149 PointsAwesome, you're welcome!
Jeffrey Cunningham
5,592 PointsJeffrey Cunningham
5,592 PointsThanks 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?