How to remove Gravatar from Username column
How to remove the Gravatar image from Username column in the All User admin page?
How to remove the Gravatar image from Username column in the All User admin page?
This is an old thread, but just in case someone else needs it: starting in version 4.2, you can use the pre_get_avatar
filter to bypass pulling the actual avatar and just sending back an empty string.
add_filter( 'pre_get_avatar', 'rkv_remove_avatar_from_list', 10, 3 );
/**
* Remove the avatar from just the user list.
*
* @param string $avatar HTML for the user's avatar. Default null.
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
* @param array $args Arguments passed to get_avatar_url(), after processing.
*
* @return string An empty string.
*/
function rkv_remove_avatar_from_list( $avatar, $id_or_email, $args ) {
// Do our normal thing on non-admin or our screen function is missing.
if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) {
return $avatar;
}
// Get my current screen.
$screen = get_current_screen();
// Bail without the object.
if ( empty( $screen ) || ! is_object( $screen ) || empty( $screen->base ) || 'users' !== $screen->base ) {
return $avatar;
}
// Return an empty string.
return '';
}
There seems to be a filter for the get_avatar
function. So I just output an empty string to it.
function remove_avatar_from_users_list( $avatar ) {
if (is_admin()) {
global $current_screen;
if ( $current_screen->base == 'users' ) {
$avatar = '';
}
}
return $avatar;
}
add_filter( 'get_avatar', 'remove_avatar_from_users_list' );
UPDATE: Restrict to 'All Users' page only.
pre_option_show_avatars
and return something that evaluates to FALSE
but isn't FALSE
. Let's say a 0
.restrict_manage_users
.restrict_manage_users-network
, but that doesn't work, so we use the filter wpmu_users_columns
and return whatever we get here.Result:
add_filter( 'wpmu_users_columns', 'no_avatars_in_user_list' );
add_action( 'restrict_manage_users', 'no_avatars_in_user_list' );
function no_avatars_in_user_list( $in = NULL )
{
add_filter( 'pre_option_show_avatars', '__return_zero' );
return $in;
}
Since there is no special avatar column to unset (the avatars are inside the username column), you could try instead to hide the avatars via css:
function hide_avatars_wpse_94126() {
if(!current_user_can('manage_options')){
// hide only for non-admins
echo "<style>.users td.username img.avatar{display:none !important;}</style>";
}
}
add_action('admin_head-users.php','hide_avatars_wpse_94126');
where they are hidden for non-admins.
The result will be like this:
Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.