How would I apply some front end CSS to a specific user role or roles?


1 Answer 1


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,
                function( $class )
                    return 'role-' . $class;    // Here we prepend the 'role-' string
                (array) wp_get_current_user()->roles 
    return $classes;
} );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.