How to get the Role Name of the current user? (WordPress)

Question

I currently have this snippet:

$user = new WP_User(get_current_user_id()); 
echo $user->roles[1];

and the output the slug of the bbPress forum role.
(roles[0] would be the general WP role but I don’t need that.)

What I need is the role name, not the slug.
So, the expected output should be something like “Keymaster”, “Participant”, “Spectator” etc.

So, how do I get the Role Name of the current user?

0
, , booster 7 months 0 Answers 103 views 0

Leave an answer