Removes a top-level admin menu.
Example usage:
remove_menu_page( 'tools.php' )remove_menu_page( 'plugin_menu_slug' )$menu_slugstringrequired
Parameter $menu_slug is the slug of the menu, typically the name of the PHP script for the built in menu items; example: edit-comments.php.
This function should be called on the admin_menu action hook. Calling it elsewhere might cause issues: either the function is not defined or the global $menu variable used by this function is not yet declared.
To remove submenu items in the admin, use remove_submenu_page() . Using remove_menu_page() will not work for submenu items.
function remove_menu_page( $menu_slug ) {
global $menu;
foreach ( $menu as $i => $item ) {
if ( $menu_slug === $item[2] ) {
unset( $menu[ $i ] );
return $item;
}
}
return false;
}
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/remove_menu_page