WordPress.org

Codex

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

Function Reference/remove menu page

Description

Remove a top level admin menu.

Please be aware that this would not prevent a user from accessing these screens directly. Removing a menu does not replace the need to filter a user's permissions as appropriate.

Usage

This function should be called on the admin_menu action hook. Calling it elsewhere could cause issues : either the function is not defined or the global $menu variable used but this function is not yet declared. <?php 
function custom_menu_page_removing() {
    
remove_menu_page$menu_slug );
}
add_action'admin_menu''custom_menu_page_removing' );
?>

Parameters

$menu_slug
(string) (required) The slug of the menu (typically the name of the PHP script for the built in menu items; example: edit-comments.php)
Default: None

Return Values

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

Examples

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().

<?php
function 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', 'remove_menus' );
?>

(*) Better to add this priority if dealing with jetpack menu: add_action( 'admin_menu', 'remove_menus', 999 );

Notes

  • Uses global: (unknown type) $menu
  • To remove submenu items in the admin, use remove_submenu_page. Using remove_menu_page() will not work for submenu items.
  • Don't use this with the admin_init hook, or $menu will not be set and the foreach() will generate many warnings during each heartbeat: "Invalid argument supplied for foreach() in wp-admin/includes/plugin.php on line 1422". Use admin_menu instead. https://core.trac.wordpress.org/ticket/17585

Change Log

Since: 3.1.0

Source File

remove_menu_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.