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:

http://mysite.co.uk/employers/executive-search

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

Leave a Reply

Your email address will not be published. Required fields are marked *