Extra Tip: Removing Admin Menus March 4, 2006
Posted by weeklytips in Uncategorized.trackback
While writing various plugins, I’ve come across the need (or want more likely) to remove some entries from the WordPress admin menus. While there isn’t an immediate API hook for this, there is still a quick bit of code to allow you to remove the items. Let’s say for example that we would like to remove the Comments menu under Manage. If you look in /wp-admin/menu.php, you’ll find something like the following (unimportant bits stripped out of course):
$menu[10] = array(__(‘Manage’), ‘edit_posts’, ‘edit.php’);
…
$submenu[‘edit.php’][20] = array(__(‘Comments’), ‘edit_posts’, ‘edit-comments.php’);
Each item in the $menu array represents a top-level menu item, while each item in the $submenu array represents one of the submenu pages. So how can we remove the menus? unset() of course.
function prefix_remove_menu() {
global $submenu;
unset($submenu[‘edit.php’][20]);
}
add_action(‘admin_header’, ‘prefix_remove_menu’);
If you really wanted, you could change that to something like this, and remove top menu items instead.
function prefix_remove_menu() {
global $menu;
unset($menu[10]);
}
add_action(‘admin_header’, ‘prefix_remove_menu’);
Thanks, this will be handy in one of my projects…
Good stuff.
I’ve also found that you can remove functionality by changing capabilities. For example, one client didn’t want to deal with the concept of Pages, so I just removed the capability to edit pages and the relevant menu items disappeared.
Good stuff.
I’ve also found that you can remove functionality by changing capabilities. For example, one client didn’t want to deal with the concept of Pages, so I just removed the capability to edit pages and the relevant menu items disappeared.
Thanks for the article (even if I am several years late)! For anyone reading this now, at least as of 2.8, the action hook is ‘admin_head’ rather than ‘admin_header’
thanks adam, i was wondering why it wasnt working.
[…] 2. James Panton – February 3, 2007 […]
[…] Extra Tip: Removing Admin Menus […]
[…] Extra Tip: Removing Admin Menus […]
nice tutorial very informative and very handy. Thanks!
Thanks, you can also remove them by editing wp-admin/menu.php file. i have a project of wordpress multisite and client want me to limit the menu functions in network, so i make a function by checking the current user ID, and disable some menu options from the network.