WordPress at a glance

remove_menu_page() WP 3.1.0

Remove a top-level admin menu item, ex: "Posts", "Media", "Pages".

Removes menu items only visually — that means that you still can visit them by their URL. After removing the menu item you still need to control a user's permissions to access the menu item page.

This function should be called on the admin_menu action hook.

To remove a submenu item, use remove_submenu_page().

No Hooks.

Return

Array/true/false. The removed menu on success, false if not found.

Usage

remove_menu_page( $menu_slug );
$menu_slug(string) (required)
The slug of the menu. It's usually the name of the file that represents the menu: upload.php.

Examples

#1 Delete menus

add_action( 'admin_menu', 'remove_menus' );
function remove_menus(){

	remove_menu_page( 'index.php' );                  // Dashboard
	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

}

Notes

  • Global. Array. $menu

Changelog

Since 3.1.0 Introduced.

Code of remove menu page: wp-admin/includes/plugin.php WP 5.2.2

<?php
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;
}

Related Functions

From tag: WP minimize (minimise reduce mitigate diminish lessen)

More from tag: Admin menu (admin panel)

No comments
    Hello, !     Log In . Register