remove_menu_page( string $menu_slug )
Remove a top-level admin menu.
Description Description
Parameters Parameters
- $menu_slug
-
(string) (Required) The slug of the menu.
Return Return
(array|bool) The removed menu on success, false if not found.
Source Source
File: wp-admin/includes/plugin.php
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 | function remove_menu_page( $menu_slug ) { global $menu ; foreach ( $menu as $i => $item ) { if ( $menu_slug == $item [2] ) { unset( $menu [ $i ] ); return $item ; } } return false; } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example
Removes every menu for all users. To remove only certain menu items include only those you want to hide within the function. To remove menus for only certain users you may want to utilize current_user_can().
/**
* Removes some menus by page.
*/
function
wpdocs_remove_menus(){
remove_menu_page(
'index.php'
);
//Dashboard
remove_menu_page(
'jetpack'
);
//Jetpack*
remove_menu_page(
'edit.php'
);
//Posts
remove_menu_page(
'upload.php'
);
//Media
remove_menu_page(
'edit.php?post_type=page'
);
//Pages
remove_menu_page(
'edit-comments.php'
);
//Comments
remove_menu_page(
'themes.php'
);
//Appearance
remove_menu_page(
'plugins.php'
);
//Plugins
remove_menu_page(
'users.php'
);
//Users
remove_menu_page(
'tools.php'
);
//Tools
remove_menu_page(
'options-general.php'
);
//Settings
}
add_action(
'admin_menu'
,
'wpdocs_remove_menus'
);
?>
Expand full source codeCollapse full source code
(*) Better to add this priority if dealing with jetpack menu: add_action( ‘admin_menu’, ‘remove_menus’, 999 );
Note that
'admin_menu'
may not be sufficient for certain menus. I’ve experienced this with a few plugins. Alternatively you can use'admin_init'
.function
wpdocs_remove_menus(){
remove_menu_page(
'some-plugin'
);
//Some Plugin Page
}
add_action(
'admin_init'
,
'wpdocs_remove_menus'
);