There’s no WordPress function to directly get the current user’s role, so I typically include my own function to serve that purpose, similar to the one below. This function is even more versatile since if you pass a specific user’s ID or User object to it, it will return that user’s role. If you pass nothing to it, you’ll get the role of the current user instead.

Note that if a user has multiple roles assigned to them, this function will only return the first role.


  1. Paul March 31, 2016 at 8:39 am


    Hello! Thanks for code. It works like charm. But I found some little mistake. In line 13 You must to put )

    • Kellen Mace April 1, 2016 at 9:30 am


      Paul- thanks for the heads up! I fixed that mistake, and also refactored the function a bit to account for when get_userdata() is unable to find the user.

  2. Pedro Lima April 23, 2016 at 11:14 am


    Works like a charm! Thank you for this simple but very useful piece of code. 🙂

  3. Adrian Monecchi December 25, 2016 at 5:53 pm


    Nice approach, it really helped me to inspect the current user’s role in the frontend. Thanks for the snippet!

  4. 083n February 26, 2017 at 10:34 am



    Can we use this with conditional logic for user roles based hooks ?
    Like this one :

    • Kellen Mace March 4, 2017 at 11:24 pm


      Yes you can. Although it looks like the bp_core_remove_nav_item() function in that example only works for the current user, so you wouldn’t want to get the role of a non-logged in user and use that BP function and expect it to work.

  5. Rachel May 19, 2017 at 4:29 pm


    Nice! This was super helpful. Thanks!

  6. LI BING ZHAO June 10, 2017 at 3:00 pm


    Thank u

  7. Thiagoveklas June 14, 2017 at 2:42 pm


    Muito levei um tempo procurando , salvou muitas horas de trabalho.
    Muito obrigado.

Leave a reply

Your email address will not be published. Required fields are marked *