W3cubDocs

/WordPress

remove_menu_page( string $menu_slug ): array|false

Removes a top-level admin menu.

Description

Example usage:

  • remove_menu_page( 'tools.php' )
  • remove_menu_page( 'plugin_menu_slug' )

Parameters

$menu_slugstringrequired
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 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.

Source

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;
}

Changelog

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