How would I apply some front end CSS to a specific user role or roles?
1 Answer
If you're looking for a way to add the roles into the body class, like here:
<body class=" ... role-administrator role-jedi role-knight ... ">
then you could try the following:
add_filter( 'body_class', function( $classes )
{
if( is_user_logged_in() )
{
$classes = array_merge(
(array) $classes,
array_map(
function( $class )
{
return 'role-' . $class; // Here we prepend the 'role-' string
},
(array) wp_get_current_user()->roles
)
);
}
return $classes;
} );