Skip to main content

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

An article from ComputerMinds - Building with Drupal in the UK since 2005
25th Mar 2011

James Williams

Senior Developer
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

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).

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.