我想使用以下代码从我的插件中添加分类模板:
add_filter( 'template_include', 'wpse_force_template' );
function wpse_force_template( $template ) {
// If the current url is an archive of any kind
if( is_tax( 'spa_products_categories' ) ) {
// Set this to the template file inside your plugin folder
$template = plugin_dir_path(__FILE__) .'archive.php';
}
// Always return, even if we didn't change anything
return $template;
}
但这不起作用,这是什么问题?