How to remove comments option from wp-admin bar and modify profile icon

To remove the comments menu from the top admin bar you can use the $wp_admin_bar global and the remove_menu() method like this:

function my_admin_bar_render() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('comments');
}
add_action( 'wp_before_admin_bar_render', 'my_admin_bar_render' );

As for changing the icon on the settings section of the left admin menu, you can modify the dashicon that is used with another. This is an example of how to change it to a globe:

function modify_settings_icon() {
    global $menu;
    $menu[80][6] = 'dashicons-admin-site';
}
add_action( 'admin_menu', 'modify_settings_icon' );

If the last snippet doesn’t work for you, just confirm the order of your menu items by debugging the global $menu array, identify the index of the Settings menu item, and modify it to your liking.

If you need to use a custom icon that isn’t in the dashicons set that ships with WordPress, you should be able to change the code above to something like $menu[80][6] = 'your-custom-icon-class'; and then add some css to add your image on that custom class.

Leave a Comment