How to add a class to a Drupal 7 region

Profile picture for user Phil Frilling
By Phil Frilling, 10 May, 2012
Today I needed to add a class to a Drupal 7 region and found the lovely template_preprocess_region() function to do the dirty work for me. With this function, you can easily add any class to your regions with the code below. In a nutshell, you find the region you want to add the class to and then append your class onto the end of the classes_array variable.

function MYTHEME_preprocess_region(&$variables) {
    // Run a switch statement to find the correct region we want to add a new class to.
    switch($variables['region']) {
      case 'left_sidebar':
        // Once we've discovered the correct region, add our new class to the classes_array.
        $variables['classes_array'][] = 'blue';
      break;
    }
}