Last active
December 30, 2015 23:39
-
-
Save dboutote/947b4e11b8d35c7b3f96 to your computer and use it in GitHub Desktop.
WordPress: Load a template file on singe-post-type page (if applicable)
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 | |
/** | |
* Load a template file on single-post-type page (if applicable) | |
* | |
* Works for all post-types | |
*/ | |
function dbdb_include_post_template($template) { | |
if( !is_archive() ) { | |
$id = get_queried_object_id(); | |
$template_name = get_post_meta($id, '_wp_page_template', true); | |
$new_template = locate_template($template_name); | |
if('' != $new_template) | |
$template = $new_template; | |
} | |
return $template; | |
} | |
add_filter( 'template_include', 'dbdb_include_post_template' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment