Add, Remove WordPress Admin Menu

WordPress admin menu is created by a single function using two global variables as parameter. See file wp-admin/menu-header.php, line 170-171 – wordpress version.3.1.1.

_wp_menu_output( $menu, $submenu );
do_action( 'adminmenu' );

To Add a top level menu item on 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 ‘my_admin_menu_function’ function is used to show the “My page” content. And this function must exists already.

To remove or unset an existing top level menu item from wordpress admin section

add_action( 'admin_head', 'remove_builtin_menu');
function remove_builtin_menu() {
	global $menu;
	$menu_file_or_pagename = 'tools.php';

	foreach( $menu as $k => $v){
		if( $menu_file_or_pagename == $v['2'])
			unset($menu[$k]);
	}
}

Just change the variable $menu_file_or_pagename to the filename of that page filename or the page slug name, like: ‘widgets.php’ or ‘pluginpage’ and place these code on your themes functions.php file.

Discussion