This tutorial is actually taken from an answer I gave on StackOverflow to a question by sailingthoms
Sailingthoms’s question
I would like to limit the +New admin menu to only show the single sub menu Event (“Veranstaltung”). Basically the users are allowed to create other items as well but not from that +New menu.
My answer
To hide everything (menu and submenu)-
1 2 3 4 5 |
function na_remove_new_content(){ global $wp_admin_bar; $wp_admin_bar->remove_menu( 'new-content' ); } add_action( 'wp_before_admin_bar_render', 'na_remove_new_content' ); |
To hide specific menu/submenu item(s)-
1 2 3 4 5 6 7 8 |
function na_remove_new_content_items(){ global $wp_admin_bar; $wp_admin_bar->remove_menu( 'new-post' ); // hides post CPT $wp_admin_bar->remove_menu( 'new-product' ); // hides product CPT $wp_admin_bar->remove_menu( 'new-page' ); // hides page CPT $wp_admin_bar->remove_menu( 'new-media' ); // hides media } add_action( 'wp_before_admin_bar_render', 'na_remove_new_content_items' ); |
So, the basic rule is-
1 2 3 4 5 |
function your_boo_bar_function() { global $wp_admin_bar; $wp_admin_bar->remove_menu( 'your-unique-menu-id' ); } add_action( 'wp_before_admin_bar_render', 'your_boo_bar_function' ); |
Add a new menu-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function na_add_menu(){ global $wp_admin_bar; $wp_admin_bar->add_node( array( 'id' => 'google-menu', 'title' => 'Google', 'href' => 'http://google.com', 'parent' => 'new-content', // so, it'll be set as a child of 'new-content'. remove this to use this as a parent menu 'meta' => array( 'class' => 'my-custom-class' ), ) ); } add_action( 'wp_before_admin_bar_render', 'na_add_menu' ); |
Update an existing menu-
1 2 3 4 5 6 7 8 9 10 11 |
function na_update_menu(){ global $wp_admin_bar; $wp_admin_bar->add_node( array( 'id' => 'new-content', // id of an existing menu 'href' => 'your_new_url_goes_here', // set new URL ) ); } add_action( 'wp_before_admin_bar_render', 'na_update_menu' ); |
How to get menu ID-
The easiest way is to inspect element with Firebug and take the ID. See this screenshot-
Navigate to your desired menu item and get the string next to wp-admin-bar-