Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As the title implies, I'm trying to set each new page under X parent to a specific page template. Either through a function/plugin/code

eg: if I make a 'swiss cheese' page, that is a children of the 'chesses' page, wp will automatically assign it the 'cheese' page template

share|improve this question
add comment

1 Answer

On the admin side, you could update the meta data for the page-post_type programmatically:

global $post;
if ( 
    'swiss_cheese' === $post->post_parent 
    AND is_admin()
    update_post_meta( $post->ID, '_wp_page_template', 'some_template.php' );

On the visitor facing side, you can simply jump into template redirect:

function wpse63267_template_redirect()
    global $post;

    if ( 'swiss_cheese' === $post->post_parent )
        include ( get_stylesheet_directory().'/swiss-cheese-template.php');
add_action( 'template_redirect', 'wpse63267_template_redirect' );
share|improve this answer
not sure what 'global $post' means and where would the admin part go? –  alme1304 Aug 28 '12 at 1:32
global $post is basic PHP and the admin part would go into a plugin or the functions.php file. of course, wrapped up in a function and hooked. –  kaiser Aug 28 '12 at 9:16
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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