Add a CSS class to the body tag of the vendor page

Is it possible to add a css class to the body tag after logging in for vendors?

Like the .logged-in class appears after logging in. For example, to have .vendor appear additionally if the user is in the vendor group.

I can provide you with this when I get home

// Creates CSS classes for the User Roles. user-role-*insert user role here*
add_filter('body_class', 'body_class_user_role');

function body_class_user_role($classes)
{

    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        $roles = $user->roles;
        $classes[] = 'user-role-' . $roles[0];
    }
    return $classes;
}

If the user is logged in, this adds a class to the body element containing the user role. If the user is a vendor (native contributer role in WordPress) then it adds a class of user-role-contributor in the body element

2 Likes

Thank you very much. That’s what I meant :slight_smile:

You are welcome :slight_smile: