3
votes

How can I set my admin theme programmatically?

Now am using public theme for anonymous users and member theme for members. Am using role theme switcher to achieve this.
Now I want my admin theme as rubik. I tried to change it from /admin/settings/admin, but it is not effecting.

Is there any way to do this? I want public theme for my site front end and rubik theme for backend.

2

2 Answers

3
votes

The admin theme is stored in the variable table; you can update it in code like so:

variable_set('admin_theme', 'theme_name');
2
votes

You can also assign a theme to a specific path.

To apply admin theme to path /SOMEPATH/*

function MYMODULE_custom_theme() {
  if (arg(0) == 'SOMEPATH') {
    return variable_get('admin_theme');
  }
}

To apply admin theme to path alias /SOMEPATH/*

function MYMODULE_custom_theme() {
  //drupal_get_path_alias() may interfere with Global Redirect module
  $arg = explode('/', substr(drupal_get_path_alias(request_uri(), 1), strlen(base_path())));
  if ($arg[0] == 'SOMEPATH') {
    return variable_get('admin_theme');
  }
}

To apply a custom theme to /admin/*

function MYMODULE_custom_theme() {
  if (arg(0) == 'admin') {
    return 'MYADMINTHEME'; //list_themes() to see available themes
  }
}

Pick a function and insert it inside your module, replacing MYMODULE with a module name.