Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How to remove the Gravatar image from Username column in the All User admin page?

enter image description here

share|improve this question

3 Answers 3

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:

Hide avatars

share|improve this answer
    
Thanks for the answer. But I just found a filter for the get_avatar function that seems to work better (see my answer). –  gmaggio Apr 2 '13 at 3:47
  1. You have to filter pre_option_show_avatars and return something that evaluates to FALSE but isn't FALSE. Let's say a 0.
  2. 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 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;
}
share|improve this answer
    
Not sure if i did it correctly but this didn't seem to do anything or me. Anyway, I already found a better filter for this. See my answer. Thanks for the answer, though. –  gmaggio Apr 2 '13 at 3:50
    
@GiraldiMaggio I tested my code on single site and multi site. –  toscho Apr 2 '13 at 4:05
    
I gave it another try, copied & pasted it, but the avatars still show. –  gmaggio Apr 2 '13 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! –  sojweb May 5 '13 at 16:04
up vote 1 down vote accepted

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.

share|improve this answer
    
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. –  toscho Apr 2 '13 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. –  gmaggio Apr 2 '13 at 4:06

Your Answer

 
discard

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.