This is what I want to accomplish. In WordPress I’ve created a taxonomy called categorie
with the terms app
, web
and branding
. When a project has the term app, I want to load another theme / blog. When a project has the term web or branding, I want to load single.php
. The last one works just fine.
This is my code so far
function load_single_template($template) {
$new_template = '';
if( is_single() ) {
global $post;
if( has_term('app', 'categorie', $post) ) {
$new_template = get_theme_roots('themeApp');
} else {
$new_template = locate_template(array('single.php' ));
}
}
return ('' != $new_template) ? $new_template : $template;
}
add_action('template_include', 'load_single_template');
So when a project has the term app
, I want to load the theme themeApp
. Any suggestions? Thanks in advance.
We had to accomplish a similar task in our plugin, AppPresser. You can see our solution here: https://github.com/WebDevStudios/AppPresser/blob/master/inc/theme-switcher.php
Basically, you need to change the theme name in 3 filters: ‘template’, ‘option_template’, ‘option_stylesheet’.
Getting the category is not so simple though, because the template check happens early enough in the WordPress process that the global
$post
and$wp_query
objects are not available.Here is one way that can be accomplished: