Skip to content

Instantly share code, notes, and snippets.

@xafarali
Created June 9, 2013 19:00
Show Gist options
  • Save xafarali/5744742 to your computer and use it in GitHub Desktop.
Save xafarali/5744742 to your computer and use it in GitHub Desktop.
Wordpress template redirection for child pages. Adopt Parent template if its assigned.
// Custom Template Inheritance -----------------------------
function custom_template_override () {
if( is_page() ) {
global $post;
if( $post->post_parent ) {
$parent_page_template = get_post_meta($post->post_parent,'_wp_page_template',true);
$current_page_template = get_post_meta($post->ID, '_wp_page_template' , true );
if ( $parent_page_template !="default" && $current_page_template == "default" ) {
include ( TEMPLATEPATH ."/". $parent_page_template );
exit;
}
}
/* echo TEMPLATEPATH."<h1>$parent_page_template</h1>";
*/
}
}
add_action( 'template_redirect','custom_template_override' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment