Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 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";
}
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

 
discard

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.