Some plugins use the 'template'
, 'option_template'
and 'option_stylesheet'
to dynamically serve (alternative) wordpress templates. For example, Nathan Rice's ServeDefaultToIESix
.
For Example -
add_filter('template', 'change_theme');
add_filter('option_template', 'change_theme');
add_filter('option_stylesheet', 'change_theme');
function change_theme()
{
// Alternate theme
return 'AwesomeTheme';
}
Above code only works from a wordpress plugin. What i need, is to switch to alternative template, located in one of the subfolders of the current theme(template). Examples: display an alternative HTML5 theme, serve mobile users a minimal version of the site.. etc.
I tried to use 'theme_root' and 'theme_root_uri' as below. But that isn't working.
// Extra lines to change the theme's root.
add_filter('theme_root', 'change_theme_root');
add_filter('theme_root', 'change_theme_root_uri');
//
add_filter('template', 'change_theme');
add_filter('option_template', 'change_theme');
add_filter('option_stylesheet', 'change_theme');
function change_theme()
{
// Display Alternate theme
return 'AwesomeTheme';
}
function change_theme_root()
{
// Return the new theme root
return WP_CONTENT_DIR . 'themes/OrigTheme/lib/AltThemes';
}
function change_theme_root_uri()
{
// Return the new theme root uri
return get_bloginfo('wpurl') . '/wp-content/themes/OrigTheme/lib/AltThemes';
}
Is this the correct way of doing it? Or does anyone know of the possible way to do so? Thanks in advance.