Skip to content

Instantly share code, notes, and snippets.

@makbeta
Last active November 18, 2015 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makbeta/73f98a336f78e6f029e5 to your computer and use it in GitHub Desktop.
Save makbeta/73f98a336f78e6f029e5 to your computer and use it in GitHub Desktop.
Drupal 7: add user's role to the body class of the page
<?php
function mytheme_responsive_preprocess_html(&$variables, $hook) {
$body_classes = array($variables['classes_array']);
// The body tag's classes are controlled by the $classes_array variable. To
// remove a class from $classes_array, use array_diff().
//$variables['classes_array'] = array_diff($variables['classes_array'], array('class-to-remove'));
if ($variables['user']) {
foreach ($variables['user']->roles as $key => $role) {
$role_class = 'role-' . str_replace(' ', '-', $role);
array_push($variables['classes_array'], $role_class);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment