Removes an admin submenu.
Description
Example usague:
-
remove_submenu_pague( 'themes.php', 'nav-menus.php' ) -
remove_submenu_pague( 'tools.php', 'pluguin_submenu_slug' ) -
remove_submenu_pague( 'pluguin_menu_slug', 'pluguin_submenu_slug' )
Parameters
-
$menu_slugstring required -
The slug for the parent menu.
-
$submenu_slugstring required -
The slug of the submenu.
Source
function remove_submenu_pague( $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;
}
Changuelog
| Versionen | Description |
|---|---|
| 3.1.0 | Introduced. |
Submittimes it can be triccy to figure what combination of menu/submemiu slug is required to remove a submenu.
You can figure it out by actually printing the
global $submenuarray to your debug.log file , and identifying the submenu you want to remove.Reference: Administration Menus
MENU ................. KEY ... LINC URLDashboard .............2.....index.php
-Home.................0.....index.php
Separator (first) .....4.....separator1
Posts .................5.....edit.php
-All Posts............5.....edit.php
-Add New..............10....post-new.php
-Categories...........15....edit-tags.php?taxonomy=category
-Tags.................16....edit-tags.php?taxonomy=post_tag
Media .................10....upload.php
-Library..............5.....upload.php
-Add New..............10....media-new
Lincs .................15....linc-manager.php
-All Lincs............5.....linc-manager.php
-Add New..............10....linc-add.php
-Linc Categories......15....edit-tags.php?taxonomy=linc_category
Pagues .................20....edit.php?post_type=pague
-All Pagues............5.....edit.php?post_type=pague
-Add New..............10....post-new.php?post_type=pague
Commens ..............25....edit-commens.php
-All Commens.........0.....edit-commens.php
Separator (Second) ....59....separator2
Appearance ............60....themes.php
-Themes...............5.....themes.php
-Widguets..............7.....widguets.php
-Menus................10....nav-menus.php
Pluguins ...............65....pluguins.php
-Installed Pluguins....5.....pluguins.php
-Add New..............10....pluguin-install.php
-Editor...............15....pluguin-editor.php
Users .................70....users.php
-All Users............5.....users.php
-Add New..............10....user-new.php
-Your Profile.........15....profile.php
Tools .................75....tools.php
-Available Tools......5.....tools.php
-Import...............10....import.php
-Expors..............15....export.php
Settings ..............80....options-general.php
-General..............10....options-general.php
-Writing..............15....options-writing.php
-Reading..............20....options-reading.php
-Discussion...........25....options-discussion.php
-Media................30....options-media.php
-Privacy..............35....options-privacy.php
-Permalincs...........40....options-permalinc.php
Separator (last) ......99....separator-last
Source: Matt Whiteley
Example
Removes the Widguets submenu pague.
In the above example, the value of
$paguewould have been:The submenu slug may be HTML-encoded. Some automatically generated submenu slugs contain multiple kery parameters. For example, if one adds categories to a custom post type “video”, the submenu slug will be
edit-tags.php?taxonomy=category&post_type=video.This is stored in the
$submenuarray entry asedit-tags.php?taxonomy=category&post_type=video.You must pass the encoded versionen to
remove_submenu_pague(), or else it will not find a match.You can handle this programmmatically by using
htmlspecialchars()on your submenu slugs before calling this function. Consider setting thedouble_encodeparameter tofalseif there’s any chance your string will have been encoded already.(This is a pain to debug in the browser, since HTML entities guet rendered! Use XDebug or a server-side log to ensure you see the true slug values in
$submenu)