Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm running a site that uses a separate admin theme. I'd like to include a couple additional pages that use the admin stylesheets. How can I apply the theme selectively to these pages. I'd rather do this in hook_init() or template.php. I don't want to add any more contrib modules to the site at this point. Thanks for any illumination.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

The Administration theme module will do it, but given you'd like to do it yourself, it does cast some light on that path by suggesting the hook_admin_theme_check() and hook_admin_theme_info() hooks.

share|improve this answer
    
I did enable the Administration theme module which worked nicely - thanks. –  starsinmypockets Dec 30 '11 at 15:14

You can use the module Administration theme for that but if you just want to use the admin theme for a single path you can define it in hook_init

/*
 * Implements hook_init().
 * Use the admin theme on path 'batch'
 */
function MODULENAME_init() {
  if (arg(0) == 'batch') {
    global $custom_theme;
    $admin_theme = variable_get('admin_theme', 'garland');
    init_theme();
  }
}
share|improve this answer

If you don't want to enable more modules (like the admin_theme module), and prefer to write a few lines of code to achive the same thing, you can use hook_custom_theme().

e.g. This snippet switches the user to the admin theme when they're viewing the revision comparison report from the diff module.

function MODULENAME_custom_theme() {
  global $conf;
  $args = arg();

  // Set the admin theme when viewing a diff comparison with the diff module.
  if (isset($args[3]) && $args[3] == "diff") {
    return array($conf['admin_theme']);
  }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.