Skip to content

Instantly share code, notes, and snippets.

@dboutote
Last active December 30, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dboutote/947b4e11b8d35c7b3f96 to your computer and use it in GitHub Desktop.
Save dboutote/947b4e11b8d35c7b3f96 to your computer and use it in GitHub Desktop.
WordPress: Load a template file on singe-post-type page (if applicable)
<?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