Skip to content

Instantly share code, notes, and snippets.

@mdjwel
Last active September 18, 2018 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdjwel/3341bbaa976ebd4c8e648991928568c2 to your computer and use it in GitHub Desktop.
Save mdjwel/3341bbaa976ebd4c8e648991928568c2 to your computer and use it in GitHub Desktop.
Get the user role in WordPress
<?php
function prefix_user_role() {
$user_meta = get_userdata(get_the_author_meta( 'ID' ));
$user_roles = $user_meta->roles; //array of roles the user is part of.
echo !empty($user_roles[0]) ? $user_roles[0] : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment