Revision: 42344
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 3, 2011 15:01 by wildpeaks
Initial Code
// 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'; $items['node/%node/edit']['theme arguments'] = array(1); } /** * 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; if (in_array(variable_get('mymodule_special_role', 0), array_keys($user->roles))) { return 'bartik'; } }
Initial URL
Initial Description
**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)
Initial Title
Drupal (6 & 7): programmatically change the active theme
Initial Tags
drupal
Initial Language
PHP