Last active
April 28, 2017 09:58
-
-
Save tomhayes/3c15047103efe551a9ed33be66e9b594 to your computer and use it in GitHub Desktop.
Add user role as a class to body
Add to functions.php
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
// Add user role as a class to body | |
if ( is_user_logged_in() ) { | |
add_filter('body_class','add_role_to_body'); | |
add_filter('admin_body_class','add_role_to_body'); | |
} | |
function add_role_to_body($classes) { | |
$current_user = new WP_User(get_current_user_id()); | |
$user_role = array_shift($current_user->roles); | |
if (is_admin()) { | |
$classes .= 'role-'. $user_role; | |
} else { | |
$classes[] = 'role-'. $user_role; | |
} | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment