change the active Drupal 7 theme programmatically

Prajila V P picture Prajila V P · Nov 16, 2011 · Viewed 7.8k times · Source

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.

Answer

Clive picture Clive · Nov 16, 2011

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.