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' )

Top ↑

Parameters

$menu_slug

(string)(Required)The slug of the menu.


Top ↑

Return

(array|false) The removed menu on success, false if not found.


Top ↑

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.

 


Top ↑

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

Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.