WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/remove submenu page

Description

Remove an admin submenu.

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.

Usage

<?php remove_submenu_page$menu_slug$submenu_slug ); ?>

Parameters

$menu_slug
(string) (required) The slug for the parent menu
Default: None
$submenu_slug
(string) (required) The slug of the submenu
Default: None

Return Values

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

Examples

Removes the Widgets submenu page.

function wpcodex_adjust_the_wp_menu() {
	$page = remove_submenu_page( 'themes.php', 'widgets.php' );
	// $page[0] is the menu title
	// $page[1] is the minimum level or capability required
	// $page[2] is the URL to the item's file
}
add_action( 'admin_menu', 'wpcodex_adjust_the_wp_menu', 999 );

In the above example, the value of $page would have been:

array(3) { [0]=> string(7) "Widgets" [1]=> string(18) "edit_theme_options" [2]=> string(11) "widgets.php" }

To remove a settings page for plugins that use a slug like /wp-admin/options-general.php?page=certain-plugin-settings use this code:

add_action( 'admin_menu', 'nstrm_remove_admin_submenus', 999 );
function nstrm_remove_admin_submenus() {
	remove_submenu_page( 'options-general.php', 'certain-plugin-settings' );
}

Remove custom post type submenu pages. The secret is in converting the second argument `&` to `&amp;`.

Notes

  • Uses global: (array) $submenu
  • 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.

Change Log

Since: 3.1.0

Source File

remove_submenu_page() is located in /wp-admin/includes/plugin.php.

Related

Administration Menus: add_menu_page(), remove_menu_page(), add_submenu_page(), remove_submenu_page(), add_dashboard_page(), add_posts_page(), add_media_page(), add_links_page(), add_pages_page(), add_comments_page(), add_theme_page(), add_plugins_page(), add_users_page(), add_management_page(), add_options_page()

See also index of Function Reference and index of Template Tags.