Problem
I made a plugin that created a custom post type, but the only way I could customize the single-customposttype.php and archive-customposttype.php is by placing the files into the theme. It would be nice if everythere could be contained in the plugin and the theme could override if needed.
Solution
WordPress to the rescue… There is a filter called ‘template_include’ that can be used to set the template. It’s a general filter so you’ll need to check for your post type.
add_filter( 'template_include', 'my_plugin_templates' );
function my_plugin_templates( $template ) {
$post_types = array( 'project' );
if ( is_post_type_archive( $post_types ) && ! file_exists( get_stylesheet_directory() . '/archive-project.php' ) )
$template = 'path/to/list/template/in/plugin/folder.php';
if ( is_singular( $post_types ) && ! file_exists( get_stylesheet_directory() . '/single-project.php' ) )
$template = 'path/to/singular/template/in/plugin/folder.php';
return $template;
}
source: http://wordpress.stackexchange.com/questions/55763/is-it-possible-to-define-a-template-for-a-custom-post-type-within-a-plugin-indep
keywords: plugin template custom post type