jump to navigation

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’);

About these ads

Comments»

1. Peter Giger - August 7, 2006

Thanks, this will be handy in one of my projects…

2. James Panton - February 3, 2007

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.

3. James Panton - February 3, 2007

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.

4. Adam - August 6, 2009

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’

5. paul - November 5, 2009

thanks adam, i was wondering why it wasnt working.

6. Extra Tip: Removing Admin Menus - January 9, 2010

[...] 2. James Panton – February 3, 2007 [...]

7. Blog Face2bouk » Blog Archive » Weekly Tip 2: Using Snoopy to Fetch Content - January 15, 2010

[...] Extra Tip: Removing Admin Menus [...]

8. Blog Face2bouk » Blog Archive » Extra Tip: Object Oriented Plugin Development - January 15, 2010

[...] Extra Tip: Removing Admin Menus [...]

9. alreymark - October 24, 2010

nice tutorial very informative and very handy. Thanks!

10. Abid - July 12, 2012

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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: