Skip to:

Display user role on profile page

  • notpoppy


    I would like to display what role a user belongs to on their profile page, e.g.: “Bob (Administrator)”, “Jane (Subscriber)”.

    I had a look on the WordPress forums and found some suggestions on how to do this but couldn’t get them to work, and wondered if it might be to do with having Buddypress installed. For example I found this:

    `$user = new WP_User( $user_id );

    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    foreach ( $user->roles as $role )
    echo $role;


    However adding this code had no effect whatsoever.

    Can anyone suggest a means of displaying a user’s role on their Buddypress profile page?

    I am also using the User Role Editor plugin ( to create an extra User Role, which may complicate things.

Viewing 2 replies - 1 through 2 (of 2 total)

  • Hugo Ashmore


    if displaying on their profile page then I don’t think you really need to loop over an array of user_id’s/roles, if you indeed do need to instantiate a new user then you probably need to pass to it bp_displayed_user_id()

    You should be able to see what you have in the $user by var_dump – ing it out to see what it has



    “probably need to pass to it bp_displayed_user_id()”

    @hnla is correct, you will need to use bp_displayed_user_id()

    as in:
    `$user_id = bp_displayed_user_id();`

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display user role on profile page’ is closed to new replies.
Skip to toolbar