Drupal - Correct way to change the active Drupal theme programmatically?

Drupal 6 solution:

You want to make sure you change the global $custom_theme variable fairly early in page execution.

global $custom_theme;
$custom_theme = 'garland';

I know you asked how to do it programattically, but in case that's your solution, not the actual problem, you can also use the ThemeKey module. This allows you to set conditions which, when met, changes the theme. You can make conditions based on paths, taxonomy, content type, create or edit date and more. You can also add in the Themekey Properties module module to get even more options.

Again, I know this isn't programmattically, but I'm not sure if the real question behind your question is how to change themes based on conditions.


The best way to do this is to create an update hook in a module:

function yourmodule_update_N() {
  variable_set('theme_default','yourtheme');
}

Tags:

Theming

6