Skip to content

Instantly share code, notes, and snippets.

@willthemoor
Forked from jancbeck/wp-role-bodyclass.php
Last active October 4, 2016 18:04
Show Gist options
  • Save willthemoor/9633329 to your computer and use it in GitHub Desktop.
Save willthemoor/9633329 to your computer and use it in GitHub Desktop.
// Add role class to body
function ns_add_role_to_body($classes) {
global $current_user;
$user_role = array_shift($current_user->roles);
// body classes are built differently on the front and back end.
// https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-admin/admin-header.php#L164
if ( ! is_admin() ) {
$classes[] = 'role-'. $user_role;
}
else {
$classes .= 'role-'. $user_role;
}
return $classes;
}
add_filter('body_class','ns_add_role_to_body');
add_filter('admin_body_class', 'ns_add_role_to_body');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment