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!

Leave a reply

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