hook_preprocess

Adding a class to <body> in a module in Drupal 7

In Drupal 6, I would often resort to using my theme's template.php file to implement template_preprocess(), and add in the class to Drupal's $body_classes array. In Drupal 7, some new hooks were introduced that allow me to do this more easily, and inside my .module files.

Introducing hook_preprocess_HOOK()

<?php
 
<br /
?>
/**
* Implements hook_preprocess_HOOK().
*/
function custom_preprocess_html(&$vars) {
$vars['classes_array'][] = 'my-class-here';
}
?>