Creating a template using a specific slug name, for a page with a parent page

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 Comment