1

I've search around but I can't seem to find exactly what I'm looking for and for the first time I don't even know where to start.

How do I display the user role (Admin, Editor, Author Contributor, Custom) next to a registered user's comments?

With a condition to display something else if they're not a registered user.

1 Answer 1

1

Just pass the user id to this function:

function get_role($user_id)
{
    if(is_int($user_id))
    {
        $user = new WP_User( $user_id );
        if ( !empty( $user->roles ) && is_array( $user->roles ) ) 
        {
            foreach ( $user->roles as $role )
                echo $role;
        }
    }
    else
        echo "Something else";
}
2
  • Does this go into comments.php or in functions.php
    – Chozen
    Mar 17, 2013 at 22:25
  • @GlentonSamuels, No different! but it's better to put it in functions.php
    – revo
    Mar 18, 2013 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.