Last active
November 18, 2015 07:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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