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-
如果要更新现有菜单项,只需使用所需菜单的ID添加新项即可。
要更新+新建(“content-New”),请使用以下代码-
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-
最简单的方法是用Firebug检查元素并获取ID。参见此屏幕截图-
导航到所需的菜单项并获取旁边的字符串
wp-admin-bar-