Dynamically assign same page template to child page as parent

Paste following code to your theme’s functions.php:

add_action('save_post','changeTemplateOnSave');
function changeTemplateOnSave(){
    global $post;
    $curr_tmp = get_post_meta($post->ID, '_wp_page_template', true);
    $parent_tmp = get_post_meta($post->post_parent, '_wp_page_template', true);
    if($post->post_parent)
        update_post_meta($post->ID,'_wp_page_template',$parent_tmp,$curr_tmp);
}

This will force WordPress to change page template to it’s parent template on post save.
Not tested but should work.

Leave a Comment