How can I exclude specific authors from wp_list_authors

I want to have the authors listed like usual from wp_list_authors() but I know there are a couple of ones I would like to exclude from the list as well. Is there a way to do that?

Thanks

Related posts

Leave a Reply

4 comments

  1. wp_list_authors() now does have an exclude parameter. So you can exclude the authors you want by their user ID.

    It accepts:

    An array, comma-, or space-separated list of author IDs to include. Default empty.

    Examples:

    // exclude just the author with the ID 4
    wp_list_authors([ 'exclude' => 4 ]);
    
    
    // exclude the authors with the IDs 4 and 7
    wp_list_authors([ 'exclude' => [ 4, 7 ] ]);
    
    // or
    wp_list_authors([ 'exclude' => '4, 7' ]);
    
  2. It seems wp_list_authors does not have any filters, nor does get_users_of_blog, the function it uses to get the user list. So you either have to regex-and-replace the output yourself, or create a similar function with an extra parameter to specify authors to exclude. It’s not too big, and most of the code is spent handling options, so it isn’t that much duplication.

    You could always vote for the existing Trac ticket to get an exclude parameter added in a future version!

  3. I have used the following code to include info from Authors (WordPress users) in a page template. It could be reversed to exclude authors.

    <?php
                //display selected users
                $userids_to_display = array(4,221,22,3,5,9,235,236,250); // wordpress user IDs to include
                $blogusers = get_users_of_blog();
                if ($blogusers) {
                  foreach ($blogusers as $bloguser) {
                    if ( in_array($bloguser->user_id, $userids_to_display) ) {
                      $user = get_userdata($bloguser->user_id);
                      echo '<div>';
                      echo '<div class="alignleft">'.get_avatar($user->ID).'</div>';
                      echo '<div class="user-data"><h3>' . $user->user_firstname . ' ' . $user->user_lastname . '</h3>';
                      echo '<div class="author-description">'.$user->description.'</div>';                
                      echo '</div>';
                    }
                  }
                }
                ?>
    
  4. Since it seems there is no way to do this without a custom function, you could use jQuery to find their names and hide them after the list is generated. Something like this:

    $('ul.author_list li:contains("John")').remove();
    

    I also found a plugin that can do this for you:
    List Authors Plus