I am customizing the WP avatar (to fit a grid) and do not want the avatar customization to show on the admin bar drop down or in the dashboard or on the site (when the admin bar is visible).

I have excluded the avatar change from the dashboard using this code in functions.php:

function foo_change_avatar($class) {
    if(!is_admin()) {
           // avatar customization code
    return $class;

How can I also prevent my customization from showing in the admin bar dropdown when the admin bar is visible on the site?

  • Why are you customizing it if you don't want to show it anywhere?
    – vancoder
    Commented Apr 9, 2013 at 21:40
  • I am showing the avatar in several places throughout the site. It's easier to exclude the admin bar and dashboard than the several other places in the site.
    – chowwy
    Commented Apr 10, 2013 at 14:59

1 Answer 1


In the WP_Admin_Bar::add_menus() class method you will find the actions:

add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 0 );
add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 );

and the two corresponding callbacks are using get_avatar().

To prevent the avatar changes in the admin bar, we can remove the foo_change_avatar filter before these callbacks and then add it again after the admin bar is rendered with the wp_after_admin_bar_render filter (it looks like this filter is not documented in the Codex):

add_action( 'admin_bar_menu', function(){

add_action( 'wp_after_admin_bar_render', function(){

So this part of the admin menu bar:

enter image description here

where the get_avatar() is used, should be excluded from the changes.

We could also have used the admin_bar_menu filter with priority greater than 7 instead of the wp_after_admin_bar_render filter.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.