drupaldrupal-7drupal-theming

Adding a class to "body"


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.


Solution

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