I have always preffered to create layout templates for specific pages by creating a filename the same as the slug.

So for example:

Page Title: Contact Us

Page Slug: contact-us

Filename of template to be used: page-contact-us.php

This always works fine for me.

However, I have one page that has a parent page. The page, with the slug executive-search has a parent of employers

For some reason, the file page-executive-search.php is not picked up as the default template for this page. This has worked fine throughout the site except for this one page. I have double-checked the page slug and it is executive-search but the page-executive-search.php template is not being used.

I do not wish to declare this as a global template to be selected from the drop-down on the edit page. I do not wish to make it chooseable through that menu. I wish it to automatically apply to a page with the slug executive-search

I am thinking this is something to do with it having a parent page. The full URL is:


So where am I going wrong?

1 Answer 1


The code used to make this decision by WordPress is get_page_template(). The pagename version (page-{slug}.php) is pulled from get_query_var( 'pagename' ), you can use this in your page.php template to see what it outputs when visiting the child page.

<?php echo get_query_var( 'pagename' ); ?>

This mostly just means that the parent slug is ignored so /employers/executive-search/ and /executive-search/ and /random/executive-search will all use the same page template of page-executive-search.php if available.

Or you can just use the ID of the page page-NN.php

  • Nope, not the case. Move page out of parent, template works. Move it in, stops working.
    – cregox
    Nov 11, 2015 at 19:34
  • Did you add the code provided to your template to see what the pagename query_var is? This should give you the suffix you need to use.
    – totels
    Nov 12, 2015 at 12:43
  • Too late, don't care anymore! ;P Haven't add pagename, but have tried it with index.php?pagename= and I'm pretty sure it was the same slug as you'd expect.
    – cregox
    Nov 12, 2015 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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