How to remove the Gravatar image from Username column in the All User admin page?
4 Answers
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:
- You have to filter
pre_option_show_avatars
and return something that evaluates toFALSE
but isn'tFALSE
. Let's say a0
. - You should restrict that filter to user list pages.
- In a single-site the proper action is
restrict_manage_users
. - In a network management screen that could be
restrict_manage_users-network
, but that doesn't work, so we use the filterwpmu_users_columns
and return whatever we get here.
- In a single-site the proper action is
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;
}
-
-
-
I gave it another try, copied & pasted it, but the avatars still show.– GiraldiApr 2, 2013 at 4:10
-
Thanks, toscho. Your solution worked well for me in 3.5.1. I run a site with a lot of users and this really sped things up for me while preserving the avatar function elsewhere. Seems to verify, at least in my case, that evaluating to false does the trick. Appreciate your help!– sojwebMay 5, 2013 at 16:04
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.
-
That would affect many more places: admin bar for example or plugin pages. Plus, this filter runs after
get_avatar()
has done all the expensive work. Way too late.– fuxia ♦Apr 2, 2013 at 3:49 -
Okay, I restricted it to 'All Users' page only. In regards to the 'late' issue, I still haven't figured that one out yet.– GiraldiApr 2, 2013 at 4:06
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 '';
}