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';

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)