in Web & Tech

Adding body classes to Drupal depending on whether a region is rendered

Here’s a simple way to add body classes to your theme in dependence of the visibility of a region. The variables array shown here is specific to the Omega theme, normally it’s something like $variables['classes_array'][]

Just put the following code into your theme’s template.php:

function MYTHEME_preprocess_html(&$variables) {
  // Add a body class if first sidebar is not being rendered
  if(!isset($variables['page']['content']['content']['sidebar_first'])) {
    $variables['attributes_array']['class'][] = 'no-sidebar-first';
  } else {
    $variables['attributes_array']['class'][] = 'sidebar-first';

Write a Comment