The WordPress admin menu is created by a single function using two global variables as parameters. You can see it in the wp-admin/menu-header.php file –
_wp_menu_output( $menu, $submenu );
do_action( 'adminmenu' );
To add a top level menu item to the WordPress admin menu section –
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
// parameters - add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL );
add_menu_page( "My admin page", "My page", 'manage_options', 'my_menu', 'my_admin_menu_function' );
}
Note: here the ‘my_admin_menu_function’ function is used to render the “My page” content. This function must already exist.
To remove an existing top level menu item from the WordPress admin section, use the remove_menu_page() function with the menu slug –
add_action( 'admin_menu', 'remove_builtin_menu', 999 );
function remove_builtin_menu() {
remove_menu_page( 'tools.php' );
}
Just change tools.php to the filename or slug of the menu page you want to remove, like ‘widgets.php’ or a plugin page slug, and place the code in your theme’s functions.php file or in a plugin. The late priority (999) makes sure the menu we want to remove is already registered. There is also a remove_submenu_page() function for removing submenu items.

Leave a Reply