remove_submenu_page()
Deletes a submenu item from the WordPress admin panel. For example, Settings > Permalinks
.
No Hooks.
Returns
Array|false
. false if the specified menu item could not be found and deleted.
Usage
remove_submenu_page( $menu_slug, $submenu_slug );
- $menu_slug(string) (required)
- The name of the menu item whose submenu needs to be deleted. Usually, this is the name of the php file responsible for displaying the page (see it in the browser's address bar).
- $submenu_slug(string) (required)
- The name of the submenu item that needs to be deleted. Usually, this is the name of the php file responsible for displaying the page (see it in the browser's address bar). It should be specified along with the query parameters and in url_encode().
Examples
#1 Let's remove the page link to the Settings->Permanent Links
page:
remove_submenu_page( 'options-general.php', 'options-permalink.php' );
Since the function is added in version 3.1, we may need to make it compatible with earlier versions of the WP, we can organize it this way by adding code to functions.php:
add_action( 'admin_menu', 'my_remove_menu_pages' ); function my_remove_menu_pages() { // WP 3.1+ if ( function_exists( 'remove_menu_page' ) ) { remove_submenu_page( 'options-general.php', 'options-discussion.php' ); } // WP below 3.1 else { unset( $GLOBALS['submenu']['options-general.php'][25] ); } }
In this example, we removed the Discussion sub-item from the settings menu:
#2 An array of menu items
Elements from this array must be specified in this function:
$menu_slug
is the key of the array.
$submenu_slug
is the third element of the array.
Notes
- Global. Array. $submenu
Changelog
Since 3.1.0 | Introduced. |
remove_submenu_page() remove submenu page code WP 6.8.1
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; }