/ Published in: PHP
                    
                                        
**Important: this snipplet has moved to Github.**
- [Programmatically change the active theme in Drupal 6](https://gist.github.com/1973197)
- [Programmatically change the active theme in Drupal 7](https://gist.github.com/1973201)
                - [Programmatically change the active theme in Drupal 6](https://gist.github.com/1973197)
- [Programmatically change the active theme in Drupal 7](https://gist.github.com/1973201)
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
// DRUPAL 6
function mymodule_init(){
global $custom_theme;
$custom_theme = 'garland';
}
// DRUPAL 7
/**
* Defines a theme callback function per registered path.
*/
function mymodule_menu_alter(&$items) {
$items['node/%node']['theme callback'] = 'mymodule_default_node_theme';
$items['node/%node/edit']['theme callback'] = 'mymodule_edit_node_theme';
}
/**
* Theme name callback: without parameters.
*/
function mymodule_default_node_theme() {
return 'garland';
}
/**
* Theme name callback: with parameters.
*/
function mymodule_edit_node_theme($node) {
return $node->type == 'page' ? 'seven' : mymodule_default_node_theme();
}
/**
* Use hook_custom_theme() if the choice of theme doesn't depend on the path.
*/
function mymodule_custom_theme() {
//Example: Changes the theme name depending if the user has a special role or not.
global $user;
return 'bartik';
}
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                