Skip to content

Instantly share code, notes, and snippets.

@Njengah
Created January 18, 2020 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Njengah/5098cee927cf2214e2dacbe2fbdd550e to your computer and use it in GitHub Desktop.
Save Njengah/5098cee927cf2214e2dacbe2fbdd550e to your computer and use it in GitHub Desktop.
Using remove_page and remove_submenu_page functions to remove admin menus WordPress
<?php
/**
* Using remove_page and remove_submenu_page functions to remove admin menus WordPress
*/
#1. Remove the main menu item together with the subpages
add_action( 'admin_menu', 'remove_admin_menu_items', 999 );
function remove_admin_menu_items() {
remove_menu_page('index.php');
}
#2. Remove the the subpages or submenu
add_action( 'admin_menu', 'remove_admin_menu_items', 999 );
function remove_admin_menu_items() {
remove_submenu_page('index.php','update-core.php' );
}
/**
* Using unset() function to remove admin menus WordPress
*/
# Testing the array for visualization
//add the action hook to admin_menu event
add_action( 'admin_menu', 'remove_admin_menu_items', 999 );
//callback function
function remove_admin_menu_items() {
//Admin menu array->List of all the WordPress admin menu items are in this array
global $submenu;
//print the array to the screen so that we can see the admin menu items by index
print('<pre>');
print_r($submenu);
print('<pre>');
// we remove everything else displayed on the screen so that see only the admin menu items array
die();
}
#1. Remove the main menu item together with the subpages using unset
add_action( 'admin_menu', 'remove_admin_menu_items', 999 );
function remove_admin_menu_items() {
global $submenu;
unset($submenu['index.php'][0]); //remove top level menu index.php (dashboard menu - Home menu )
unset($submenu['index.php'][10]); // remove the submenu update-core.php (updates menu)
}
#2. Remove the main submenu item using unset
add_action( 'admin_menu', 'remove_admin_menu_items', 999 );
function remove_admin_menu_items() {
global $submenu;
unset($submenu['index.php'][10]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment