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


How to Stop WordPress Plugin Shortcode from Duplicating on Reload

It can be frustrating when your WordPress shortcodes duplicate content on page reload. This usually ...

CSS in WordPress: Single Stylesheet vs. Page-Specific Files – What’s Best?

WordPress developers often face the dilemma of choosing between a single consolidated CSS file or mu...

How to Fix CSP Inline Script & Style Issues in WordPress

Content Security Policy (CSP) is a crucial security layer that helps protect your WordPress site fro...

WordPress Force HTTPS Without Plugin: The Ultimate Method

Hey there! Are you running a WordPress website on WP Engine and want to make it more secure? Worried...

Recent Posts