Template naming convention conflicts with page slug.

  • Resolved
    Posted in: Highend WP Theme  
  • Customer
    AmandaB
    June 13, 2014 at 9:16 pm #3620

    I wanted to have a page at /contact/ which does not use the contact template included with the theme, but no matter what template I chose for that page, it kept using the contact one. Turns out to be a very simple cause, but it took me a good while to realize what was going on. According to WordPress’s template hierarchy, page-{slug}.php will be applied to any page with a matching slug. So if page-contact.php exists, a page with its slug set to ‘contact’ will always use that file.

    I know I can just rename the file, but I prefer making all modifications to the child theme. For now, I will copy the default page template to the child theme, and name it page-contact.php.

    So I’ve got it sorted, but I thought it was something you should know about. What I’ve seen other theme developers do to avoid this conflict is to use ‘template’ instead of ‘page’ in their file name. So in this example, the file would be named template-contact.php.

    Sorry, this forum is for verified users only. Please Login or Register to continue

Comments are closed.