• Resolved ofmarconi

    (@ofmarconi)


    Hi!

    Could you tell me how to add to BodyClass the class referring to the current user’s roll?

    If this is not possible, I would like to request this feature.

    So we can change the style according to user role, and even hide with display: None some things.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Caseproof

    (@caseproof)

    Hi @ofmarconi

    To add roles names to body classes you can add this code at the end of your theme’s functions.php file:

    add_filter( 'body_class', function( $classes ) {
    	$user = wp_get_current_user();
    	$roles = $user->roles;
        return array_merge( $classes, $roles );
    } );

    This will add ‘subscriber’, ‘editor’, and other role names that currently logged-in user has to body class, so you could select it with CSS.

    Hopefully, that helps.

    Thread Starter ofmarconi

    (@ofmarconi)

    THX!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Body Class for user role’ is closed to new replies.