WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

Just pass the user id to this function:

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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