template info is empty if load_template()
-
hi
thanks for this awesome tool, helps a lot, while developing. i have a very small issue, no big deal, but i thought i’d report it.
if i switch the template via functions.php, the “template name” field is empty. i tried to change the add_action prority, but that did not help. absolutly no big deal, the list works just fine.
thank you for this toolhere is the code, i use in functions.php to change the template, based on the parent page ID:
function is_child( $pid ) { global $post; $ancestors = get_post_ancestors( $post->$pid ); $root = count( $ancestors ) - 1; $parent = $ancestors[$root]; if( is_page() && ( is_page( $pid ) || $post->post_parent === $pid || in_array( $pid, $ancestors ) ) ) { return true; } else { return false; } }; function switch_template( $tpl ) { $template = get_stylesheet_directory() . "/" . $tpl; if ( file_exists( $template ) ) { load_template( $template ); exit; } }; function wpse140605_template_redirect() { if ( is_child( 20 ) || is_child( 22 ) ) { // lookbook switch_template( 'single-lookbook.php' ); } }; add_action( 'template_redirect', 'wpse140605_template_redirect', 10, 0 );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘template info is empty if load_template()’ is closed to new replies.