• Resolved angeloarlotta

    (@angeloarlotta)


    Hi,
    is it possible to add a user role class into any page of the website to target CSS codes specifically for different users basing on their role?

    Now the user role class is shown only on UM modules: um-role-subscriber, um-role-administrator and so on..

    Thanks in advance!

    Angelo

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @angeloarlotta

    It depends on your theme if it has the body_class function.

    You can try adding this code snippet to add the UM role in the body class:

    add_filter( 'body_class', function( $classes ) {
        $user_id = get_current_user_id();
        um_fetch_user( $user_id );
        $role = um_user("role");
    
        return array_merge( $classes, array( 'um_role-'.$role ) );
    } );

    The above code will add the currently logged-in user’s role to the body_class.

    Regards,

    Thread Starter angeloarlotta

    (@angeloarlotta)

    Thank you @champsupertramp it works perfectly!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @angeloarlotta

    Thanks for letting us know.

    Regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘User role class into body’ is closed to new replies.