使用filter template_include
替代模板路径。示例:
add_filter( \'template_include\', function( $template ) {
if ( ! is_singular() ) {
return $template;
}
if ( \'project\' !== get_post_type() ) {
return $template;
}
// Now we can safefely
return get_stylesheet_directory() . \'/single-project.php\';
});