I want to list pictures of all avatars how do I do this
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can jump start by using following example. Here I’ll be listing users and loop through them to display avatar and display name.
<?php
$blogusers = get_users();
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
/* Here passing user email and avater size */
echo get_avatar( $user->user_email , 96 );
echo '<span>' . esc_html( $user->display_name ) . '</span>';
}
Read more about
Method 2
- You have to retrieve all users with this get_users() and loop through them.
- Then you have to get the avatar URL using a current user id with this get_avatar_url().
$users = get_users( array( 'fields' => array( 'ID' ) ) );
// Array of stdClass objects.
foreach ( $users as $user ) :
$avatar = get_avatar_url( $user->ID );
// If you want to retrieve specifc size image.
// $avatar = get_avatar_url( $user->ID, array( 'size' => '300') );
if ( $avatar ) :
echo '<img src=" ' . esc_url( $avatar ) . ' " />';
endif;
endforeach;
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0