Author image
Senior Developer

Setting default drupal theme during installation : programatically install a drupal theme

Here's a quick post that will be a reminder for us as much as anyone else! Setting the default theme during installation using an installation profile is surprisingly hard in Drupal 6, and easier though not obvious in Drupal 7. In Drupal 6, we used the wonderful Install Profile API module, which allowed us to do it in just a few lines in an install task:

  install_enable_theme(array('my_theme', 'garland', 'rubik'));

In Drupal 7, here's the code I use in my install task:

  // Any themes without keys here will get numeric keys and so will be enabled,
  // but not placed into variables.
  $enable = array(
    'theme_default' => 'iexplore',
    'admin_theme' => 'seven',

  foreach ($enable as $var => $theme) {
    if (!is_numeric($var)) {
      variable_set($var, $theme);

  // Disable the default Bartik theme

Nice and simple now that we have theme_enable() and theme_disable()! There are also the maintenance_theme and node_admin_theme variables that can be set, to define a theme for maintenance mode and whether the admin theme should be used on node forms respectively (in either Drupal 7 or Drupal 6).