Created
March 4, 2012 14:23
-
-
Save cecilemuller/1973201 to your computer and use it in GitHub Desktop.
Programmatically change the active theme in Drupal 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Defines a theme callback function per registered path. | |
*/ | |
function MODULENAME_menu_alter(&$items) { | |
$items['node/%node']['theme callback'] = 'MODULENAME_default_node_theme'; | |
$items['node/%node/edit']['theme callback'] = 'MODULENAME_edit_node_theme'; | |
$items['node/%node/edit']['theme arguments'] = array(1); | |
} | |
/** | |
* Theme name callback: without parameters. | |
*/ | |
function MODULENAME_default_node_theme() { | |
return 'garland'; | |
} | |
/** | |
* Theme name callback: with parameters. | |
*/ | |
function MODULENAME_edit_node_theme($node) { | |
return $node->type == 'page' ? 'seven' : MODULENAME_default_node_theme(); | |
} | |
/** | |
* Use hook_custom_theme() if the choice of theme doesn't depend on the path. | |
*/ | |
function MODULENAME_custom_theme() { | |
//Example: Changes the theme name depending if the user has a special role or not. | |
global $user; | |
if (in_array(variable_get('MODULENAME_special_role', 0), array_keys($user->roles))) { | |
return 'bartik'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very nice