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 am using this code for listing out all authors on the site in my sidebar. It works, except I also need to pull in their Gravatar image. It's working in a loop on the homepage with this

<?php echo get_avatar( get_the_author_email(), '80' ); ?>

but is there a way I can add it to this list as well? Also.. I can't figure out a way to exclude the "Admin" account using this code, is that possible?

Thank you!

$order = 'user_nicename';
$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
foreach($user_ids as $user_id) : 
$user = get_userdata($user_id);
<li><?php echo '<a href="' . $user->user_url . '">' . $user->display_name . '</a>'; ?><br /></li>
share|improve this question
up vote 3 down vote accepted

Basic setup


    $args = array( 'orderby' => 'nicename' );
    $users = get_users( $args ); 

    foreach ( $users as $user ) {
        $avatar = get_avatar( $user->ID, '80' );
        echo '<li><a href="' .
                $user->user_url .
            '">' .
                $avatar . '<br />' .
                $user->display_name .


Excluding the Admin User

Either check in the foreach:

foreach ( $users as $user ) {
    if( ! in_array( 'administrator', $user->roles ) ) {
        // echo user list

or if all other users are subscribers, include the role parameter as an argument for the user query:

$args = array(
    'orderby' => 'nicename',
    'role' => 'subscriber'

or, if you have but one (or few static) admin user, exclude him/her from the query by id:

$args = array(
    'orderby' => 'nicename',
    'exclude' => array( 1, 23 ) //adjust
share|improve this answer
get_users should have a roles parameter that accepts multiple arguments as an array. Even better also an exclude_roles paramater. – Johannes Pille Oct 17 '12 at 18:44

Here's a simple example showing default avatars and lists all users with the role of author.

foreach ( get_users( array( 'role' => 'author'  ) ) as $user )
    echo get_avatar(
share|improve this answer

use <?php echo get_avatar( $user->ID, '80' ); ?>, somewhere inside the foreach loop

If you're looking to exclude a particular user, you can use it's id($user->ID) or username($user->user_login) or if you want to exclude all the administrators, you can use if(current_user_can('promote_users')) continue; as the first line of foreach. Check out the reference for more info


share|improve this answer

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.