Created
August 16, 2012 16:53
-
-
Save claudiosanches/3371633 to your computer and use it in GitHub Desktop.
Manipulate Child Pages to Use Parent Page Templates Automatically
This file contains hidden or 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 | |
// Manipulate Child Pages to Use Parent Page Templates Automatically | |
function switch_page_template() { | |
global $post; | |
// Checks if current post type is a page, rather than a post | |
if (is_page()) { | |
$current_page_template = get_post_meta($post->ID, '_wp_page_template', true); | |
if (!$current_page_template) { | |
$parent_page_template = get_post_meta($post->post_parent, '_wp_page_template', true); | |
$parents = (is_page() && $post->post_parent == $post->ID) ? true : false; | |
if ($parents == true) { | |
update_post_meta($post->ID, '_wp_page_template', $parent_page_template, $current_page_template); | |
} | |
} | |
} | |
} | |
add_action('save_post', 'switch_page_template'); | |
add_action('the_post', 'switch_page_template'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment