A while back I found that there was a reason to name a template like so


For the life of me, I can't remember what it was for. I thought it was so that WordPress would automatically pick up that template so that you would not have to set the page template when creating the post. I have been looking in the codex for an hour and can't find it. Do you know what the logic is behind this?

  • There is no logic; you can name your templates krafutzel.php and they will work. – fuxia Aug 22 '12 at 5:08

I always name them like so: page-name.php; This keeps my page templates nicely together + in some cases this can make your code easier, for example...

<?php // Get the file called loop-page.php
get_template_part( 'loop', 'page' ); ?>

A quick Google revealed also this http://wp.tutsplus.com/tutorials/organizing-and-naming-your-themes-template-files-for-clarity-and-convenience/



Ok, I found it on codex - Page Display

Quote from Codex -

  • custom template file - The Page Template assigned to the Page. See get_page_templates().
  • page-{slug}.php - If the page slug is recent-news, WordPress will look to use page-recent-news.php
  • page-{id}.php - If the page ID is 6, WordPress will look to use page-6.php
  • page.php
  • index.php
  • yes, there was some good information posted by Amit and Marcup. I thought you could name templates by the name of a custom post type and WordPress would pick up that template automatically. I think maybe the page-name.php might do that. – Jamie Aug 22 '12 at 22:42
  • Yeah. You can use page-customposttype.php, single-customposttype.php, etc. – Jake Aug 23 '12 at 6:18
  • Yes, page-ID.php then no need to manually assigne page template on save. – amit Aug 23 '12 at 6:24
  • for some reason when I try this, it doesn't work. Here is what I thought. If I have a custom post type called "gallery" I should be able to set up a file called page-gallery.php and wordpress would pick it up automatically so I would not need to set the template name on the page. But when I try that logic, it doesn't work. I could have sworn I did this before – Jamie Aug 31 '12 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.