2

What is the correct way to change the active Drupal theme programmatically?

markdorison
  • 139,374
  • 27
  • 55
  • 71
  • What do you mean by "changing a theme programmatically". Customize a downloadable theme for a site? Alter the theme without modyfying it's files or something else? – googletorp Oct 21 '10 at 19:05
  • Edited question to clarify. What I meant was how do I change the active theme. – markdorison Oct 21 '10 at 19:49

1 Answers1

7

Edit: here is a simpler example.

It uses Garland regardless of the theme setting. Note that this overrides the admin theme setting too.

function MODULENAME_init(){
    global $custom_theme;
    $custom_theme = 'garland';
}

Edit: changing globally.

And if you meant changing the theme setting in the database instead of just on the current page, here is how:

// Changes the theme to Garland
variable_set('theme_default', 'garland');

// Changes only the administration theme to Garland
variable_set('admin_theme', 'garland');
wildpeaks
  • 7,273
  • 2
  • 30
  • 35
  • 1
    The global $custom_theme variable is probably what you're looking for, but it should be modified early enough for the whole page to use only one theme, and hook_init is a good location to do that. – wildpeaks Oct 21 '10 at 21:24
  • What if you just want to make the admin theme active? – markdorison Oct 25 '10 at 17:02