How to Remove WordPress Admin Bar Items

Updated on:

I disable the admin bar for all users including myself and the only time I see it is when I am doing something on my WordPress dashboard.

I was wondering how to remove some of the items from it and I found a code snippet which might help you do that

There are probably other ways to do it but this code snippet did what it was supposed to.

Let’s check it out

Code Snippet

This is the code snippet that you can use to remove different type of items

function remove_admin_bar_items($wp_admin_bar) {
	
	$wp_admin_bar->remove_node('wp-logo');
	$wp_admin_bar->remove_node('comments');
	$wp_admin_bar->remove_node('new-content');
	$wp_admin_bar->remove_node('gp_elements-menu');
}
add_action('admin_bar_menu', 'remove_admin_bar_items', 999);

I removed five of the four items that you can see in the image below:

Remove Admin Bar Items

To find other the name of other items you need to inspect the code.

How to Remove Comments from WordPress Admin Bar

Do you want to remove comments from your WordPress admin bar? It’s easy with this code snippet.

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

Why a Snippets Plugin?

You can add the snippet to your functions.php file but I totally recommend against that because if you add many code snippets, eventually that will turn file into a mess.

Also you might lose the changes when you update your WordPress theme so you better use a code snippets plugin.

JM

Sobre Jose Manuel

I am José Manuel. I am writing about things I know and things that I am learning about WordPress. I hope you find this blog useful.