Adding a class to "body"

Chris Muench picture Chris Muench · Oct 9, 2011 · Viewed 39k times · Source

How can I modify or pre-process the <body> tag to add the class body? I don't want to create a whole html.tpl.php just to add a class.

Answer

Clive picture Clive · Oct 9, 2011

In your theme's template.php file use the preprocess_html hook:

function mytheme_preprocess_html(&$vars) {
  $vars['classes_array'][] = 'new-class';
}

Remember to clear the caches once you've implemented the hook or Drupal won't pick it up.