提供可由主题挂钩覆盖的默认模板template_include
就像链接的问题所暗示的那样。你得到了WordPress想要用作参数的模板。如果这不是您想要的文件,请将其替换为您插件的文件:
add_filter( \'template_include\', \'wpse_57232_render_cpt\', 100 );
/**
* Provide fall back template file for a custom post type single view.
*
* @return void
*/
function wpse_57232_render_cpt( $template )
{
// Our custom post type.
$post_type = \'my_custom_cpt\';
// WordPress has already found the correct template in the theme.
if ( FALSE !== strpos( $template, "/single-$post_type.php" ) )
{
// return the template in theme
return $template;
}
// Send our plugin file.
if ( is_singular() && $post_type === get_post_type( $GLOBALS[\'post\'] ) )
{
// return plugin file
return dirname( __FILE__ ) . "/single-$post_type.php";
}
// Not our post type single view.
return $template;
}