Created
June 9, 2013 19:00
-
-
Save xafarali/5744742 to your computer and use it in GitHub Desktop.
Wordpress template redirection for child pages.
Adopt Parent template if its assigned.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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