How to Remove Menu Items from the WordPress 3.3 Admin Bar

Home » Snippets » How to Remove Menu Items from the WordPress 3.3 Admin Bar
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

WordPress is a powerful platform that offers a wide range of customization options. One of the most useful features of WordPress is the admin bar, which provides quick access to important functions of your website. However, sometimes you may want to remove certain menu items from the admin bar in order to simplify the user interface or to prevent certain users from accessing specific functions. In this article, we’ll show you how to remove menu items from the WordPress 3.3 admin bar to help you better customize your user experience.

					function wpturbo_remove_admin_bar_menu_items() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu( 'wp-logo' ); // remove WordPress logo
    $wp_admin_bar->remove_menu( 'comments' ); // remove comments
    $wp_admin_bar->remove_menu( 'new-content' ); // remove new content
}
add_action( 'wp_before_admin_bar_render', 'wpturbo_remove_admin_bar_menu_items' );
				

In this article, we will explore how to remove menu items from the WordPress 3.3 admin bar using PHP code.

The code snippet above achieves this by defining a new function called wpturbo_remove_admin_bar_menu_items(). This function will remove specific menu items from the WordPress admin bar.

To achieve this, we first create a global variable $wp_admin_bar inside the function. This variable is used to reference the WordPress admin bar.

Once we have defined the variable, we call the $wp_admin_bar->remove_menu() function to remove the specific menu items we wish to hide.

To hide the WordPress logo, we use the following line of code:

$wp_admin_bar->remove_menu('wp-logo');

To hide the comments menu item, we use the following line of code:

$wp_admin_bar->remove_menu('comments');

And to remove the "new content" menu item, we use the following line of code:

$wp_admin_bar->remove_menu('new-content');

By combining these three lines of code, we can remove these three menu items from the WordPress 3.3 admin bar. We then add the wpturbo_remove_admin_bar_menu_items() function to the wp_before_admin_bar_render action to ensure that WordPress executes this code when it renders the admin bar.

It’s essential to note that this function only hides the menu items from the admin bar. The functionality of the items remains intact.

Register an account to save your snippets or go Pro to get more features.