remove_submenu_page() WordPress Function

The remove_submenu_page() function allows you to remove a submenu page from a parent menu page. This function takes two parameters: the parent menu page slug and the submenu page slug.

remove_submenu_page( string $menu_slug, string $submenu_slug ) #

Removes an admin submenu.


Description

Example usage:

  • remove_submenu_page( 'themes.php', 'nav-menus.php' )
  • remove_submenu_page( 'tools.php', 'plugin_submenu_slug' )
  • remove_submenu_page( 'plugin_menu_slug', 'plugin_submenu_slug' )

Top ↑

Parameters

$menu_slug

(string)(Required)The slug for the parent menu.

$submenu_slug

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


Top ↑

Return

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


Top ↑

More Information

Depending on when this function is called, it may not prevent users from accessing the screen for the removed submenu directly (see ticket #18850). Removing a menu does not replace the need to filter a user’s permissions as appropriate.

In order to remove the theme-editor.php submenu of themes.php (and others) in more recent versions of WordPress, you need to bind to the admin_menu hook with a very high priority (about 110, depending on the submenus to remove). Don’t use admin_init as previously stated here, hence it will break wp-admin/admin-ajax.php.


Top ↑

Source

File: wp-admin/includes/plugin.php

function remove_submenu_page( $menu_slug, $submenu_slug ) {
	global $submenu;

	if ( ! isset( $submenu[ $menu_slug ] ) ) {
		return false;
	}

	foreach ( $submenu[ $menu_slug ] as $i => $item ) {
		if ( $submenu_slug === $item[2] ) {
			unset( $submenu[ $menu_slug ][ $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.