remove_menu_page() WordPress Function
The remove_menu_page() function is used to remove a top-level menu page from the WordPress admin menu.
remove_menu_page( string $menu_slug ) #
Removes a top-level admin menu.
Description
Example usage:
remove_menu_page( 'tools.php' )
remove_menu_page( 'plugin_menu_slug' )
Parameters
- $menu_slug
(string)(Required)The slug of the menu.
Return
(array|false) The removed menu on success, false if not found.
More Information
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 but 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.
Source
File: wp-admin/includes/plugin.php
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |