What is the correct way to change the active Drupal 7 theme programmatically? I used $custom_theme
in Drupal 6 but it is not working in Drupal 7.
You can use hook_custom_theme()
:
function mymodule_custom_theme() {
if ($some_condition_is_true) {
return 'my_theme';
}
}
If you need to base your selection on the path then the best way to go is to override the theme callback
for particular menu router items. See here for an example.