Skip to content

Instantly share code, notes, and snippets.

@nelsson
Forked from jancbeck/wp-role-bodyclass.php
Created November 27, 2017 17:02
Show Gist options
  • Select an option

  • Save nelsson/dfbbe6d5db124d910d6e4a8fb39449f3 to your computer and use it in GitHub Desktop.

Select an option

Save nelsson/dfbbe6d5db124d910d6e4a8fb39449f3 to your computer and use it in GitHub Desktop.
WordPress: Add user role class to body tag
<?php
// Add role class to body
function add_role_to_body($classes) {
global $current_user;
$user_role = array_shift($current_user->roles);
$classes .= 'role-'. $user_role;
return $classes;
}
add_filter('body_class','add_role_to_body');
add_filter('admin_body_class', 'add_role_to_body');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment