Remove Specific Admin Menu Items in WordPress

Anders T Dec 28, 2024 Admin Customization
How do I get rid of some options from the menu that my website managers see in the admin area?
What code snippet can I implement to remove specific admin menu items for certain user roles in WordPress using the `remove_menu_page()` function?
Andy answered Dec 28, 2024

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:

  1. Admin Menu Editor - Provides a visual interface to customize the admin menu
  2. User Role Editor - Manage user capabilities and menu access
  3. 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.