How to remove admin menu pages inserted by plugins?

To remove admin menu pages inserted by plugins in WordPress, you typically use the remove_menu_page() or remove_submenu_page() functions, hooked into the admin_menu action.

Here’s how you can do it:

1. Identify the Menu Slug

The most crucial step is to find the correct “slug” of the menu item you want to remove.

For top-level menus: Hover over the menu item in your WordPress admin area. Look at the URL that appears in your browser’s status bar (usually at the bottom left). The slug is typically the part after admin.php?page= or the PHP file name itself (e.g., tools.php, plugins.php, edit.php?post_type=your_custom_post_type).

For submenu items: You’ll need both the parent menu’s slug and the submenu item’s slug. Again, hover over the submenu item and look at the URL. The parent slug is usually the main menu’s PHP file (e.g., options-general.php for Settings), and the submenu slug is the specific page’s PHP file or page= parameter.

If you’re having trouble finding the slug, you can temporarily add a debugging function to your functions.php file to print out all registered menu and submenu items.

// Add this to your functions.php temporarily to find menu slugs
function debug_admin_menus() {
    if ( ! is_admin() ) return;
    global $submenu, $menu;
    echo '<pre>';
    print_r( $menu ); // Top-level menus
    print_r( $submenu ); // Submenus
    echo '</pre>';
}
add_action( 'admin_notices', 'debug_admin_menus' );

After adding this, visit your dashboard, and you’ll see a dump of the $menu and $submenu global arrays, which contain the slugs. Remember to remove this debugging code once you have the slugs.

2. Use remove_menu_page() for Top-Level Menus

To remove a top-level menu item, use remove_menu_page():

3. Use `remove_submenu_page()` for Submenu Items

To remove a submenu item, you need to specify both the parent menu slug and the submenu slug:

Where to Place the Code

You should place this PHP code in your theme’s `functions.php` file or, even better, in a custom plugin. Using a custom plugin is generally recommended for site-specific functionalities, as it keeps your changes independent of theme updates.

Important Considerations:

  • Hook: Always use the `admin_menu` action hook. Using `admin_init` can sometimes lead to issues because the global `$menu` and `$submenu` variables might not be fully populated yet.
  • Priority: The third parameter in `add_action()` is the priority. A higher number (like `999`) ensures your function runs *after* most other functions that add menu items, including those from plugins. This is crucial for successful removal.
  • Permissions: Removing a menu item only hides it visually. It does *not* prevent users from accessing the page directly if they know the URL and have the necessary capabilities. If you need to restrict access based on user roles, you should implement proper capability checks.
  • Plugin Updates: If a plugin updates and changes its menu slug, your code might stop working. You’ll need to re-identify the new slug and update your code accordingly.

By following these steps, you can effectively remove unwanted admin menu pages inserted by plugins, helping to declutter your WordPress dashboard.

Related Posts


Elementor Missing Features? Here’s How I Added a 5-Post Tile News Section Manually

Elementor is a powerful page builder, but sometimes its built-in widgets might not offer the exact l...

Media Gallery Preview Images Not Updating After Replacing via Media Library (WPBakery Grid Fix)

Troubleshooting Guide: WPBakery Media Grid Thumbnails Not Updating This guide will help you resolve ...

Why Your Post Counts Are Wrong on Multilingual Sites (And How to Fix It)

Managing a multilingual website can be a complex endeavor, and one common issue that often goes unno...

Auto create an user account after WooCommerce checkout without Plugin

To automatically create a user account after WooCommerce checkout, you can use the woocommerce_thank...

Recent Posts