How to add a class to a Drupal 7 region?

Heinen Creative picture Heinen Creative · Jul 20, 2011 · Viewed 11.5k times · Source

I am trying to add a .clearfix class to my footer region in a Drupal 7. Is there a way to do this?

I am currently using the following to print my footer region:

<?php print render($page['footer']); ?>

Which outputs:

<div class="region region-footer">
   <div id="block-1>....</div>
   <div id="block-2>....</div>
</div>

Answer

snufft picture snufft · Jan 10, 2013

Here's the code snippet:

function MY_THEME_NAME_preprocess_region(&$variables, $hook) {
    if($variables['region'] == "MY_REGION_NAME"){
        $variables['classes_array'][] = 'MY_CLASS_NAME';
    }
}

Or if you'd rather insert the class into all of the regions:

function MY_THEME_NAME_preprocess_region(&$variables, $hook) {
    $variables['classes_array'][] = 'MY_CLASS_NAME';
}