How to Remove Admin Menu Items
Custom Code Solution
The following code removes specific menu items from the WordPress admin area. You can customize it by adding or removing items based on your needs.
Place this code in your theme's functions.php
file or in a site-specific plugin:
This code removes menu items for all users except administrators:
function remove_admin_menu_items() {
if (!current_user_can('administrator')) {
remove_menu_page('tools.php'); // Tools
remove_menu_page('edit-comments.php'); // Comments
remove_menu_page('edit.php'); // Posts
remove_menu_page('plugins.php'); // Plugins
}
}
add_action('admin_menu', 'remove_admin_menu_items', 999);
To remove specific submenu items, use this code:
function remove_admin_submenus() {
if (!current_user_can('administrator')) {
remove_submenu_page('options-general.php', 'options-writing.php'); // Writing
remove_submenu_page('options-general.php', 'options-reading.php'); // Reading
remove_submenu_page('options-general.php', 'options-discussion.php'); // Discussion
}
}
add_action('admin_menu', 'remove_admin_submenus', 999);
Common menu slugs for reference:
// Main menu slugs
'index.php' // Dashboard
'edit.php' // Posts
'upload.php' // Media
'edit.php?post_type=page' // Pages
'edit-comments.php' // Comments
'themes.php' // Appearance
'plugins.php' // Plugins
'users.php' // Users
'tools.php' // Tools
'options-general.php' // Settings
Plugin Solutions
If you prefer a plugin solution, here are reliable options:
-
Admin Menu Editor - Provides a visual interface to customize the admin menu
-
User Role Editor - Manage user capabilities and menu access
-
AdminimizeX - Hide admin menu items based on user roles
Additional Tips
- Use priority 999 in the
add_action
to ensure your changes run after the menu is built
- Test thoroughly after implementing changes
- Consider using user roles instead of specific capabilities for better maintainability
- Always keep administrator access to prevent accidentally locking yourself out
Remember to adjust the code based on your specific needs and test it in a development environment first.