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;
}
add_filter('get_avatar','foo_change_avatar');
How can I also prevent my customization from showing in the admin bar dropdown when the admin bar is visible on the site?
In the
WP_Admin_Bar::add_menus()
class method you will find the actions: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 thewp_after_admin_bar_render
filter (it looks like this filter is not documented in the Codex):So this part of the admin menu bar:
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 than7
instead of thewp_after_admin_bar_render
filter.