Created
January 22, 2014 19:04
-
-
Save kisabelle/8565154 to your computer and use it in GitHub Desktop.
WordPress: Automatically Apply Parent Page Template to Child Pages by Matovu Richard
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
<?php | |
function switch_page_template() { | |
global $post; | |
// Checks if current post type is a page, rather than a post | |
if (is_page()) | |
{ | |
// Checks if page is parent, if yes, return | |
if ($post->post_parent == 0) | |
return true; | |
else if ($post->post_parent != $post->ID) | |
{ | |
$parent_page_template = get_post_meta($post->post_parent,'_wp_page_template',true); | |
$template = TEMPLATEPATH . "/{$parent_page_template}"; | |
if (file_exists($template)) { | |
load_template($template); | |
exit; | |
} | |
} | |
} | |
} | |
add_action('template_redirect','switch_page_template'); | |
/* Source: http://www.matrich.net/blog/wordpress/how-to-automatically-apply-parent-page-template-to-all-sub-pages-in-wordpress.htm */ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: http://www.matrich.net/blog/wordpress/how-to-automatically-apply-parent-page-template-to-all-sub-pages-in-wordpress.htm