How to remove items from +New admin menu?

To hide everything (menu and submenu)-

function wpse_260669_remove_new_content(){
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu( 'new-content' );
}
add_action( 'wp_before_admin_bar_render', 'wpse_260669_remove_new_content' );

To hide specific menu/submenu item(s)-

function wpse_260669_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', 'wpse_260669_remove_new_content_items' );

So, the basic rule is-

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-

function wpse_260669_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', 'wpse_260669_add_menu' );

Update an existing menu-

If you want to update an existing menu item, just add a new item using the ID of your desired menu.

To update +New (‘content-new’), use this code-

function wpse_260669_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', 'wpse_260669_update_menu' );

How to get menu ID-

The easiest way is to inspect element with Firebug and take the ID. See this screenshot-

How to get menu ID

Navigate to your desired menu item and get the string next to wp-admin-bar-

Leave a Comment