remove_submenu_page( string $menu_slug, string $submenu_slug )

Remove an admin submenu.


Description Description


Parameters Parameters

$menu_slug

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

$submenu_slug

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


Top ↑

Return Return

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


Top ↑

Source 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

Changelog
Version Description
3.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Example
    Removes the Widgets submenu page.

    /**
     * Remove the Widgets submenu page.
     */
    function wpdocs_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', 'wpdocs_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" }
    

You must log in before being able to contribute a note or feedback.