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 List Posts on a Page Using ACF Field Values in Shortcodes?

Here’s how you can list posts on a page using ACF field values within a shortcode. This soluti...

How to fork and maintain a WooCommerce Block separately?

Forking and maintaining a WooCommerce block allows you to customize its functionality independently ...

How to Set Default Attributes for New Blocks Without Affecting Existing Ones

When working with block-based content editors, a common need is to establish default attributes for ...

Why WordPress Looks for .htaccess in the Wrong Directory When Using WP_HOME and WP_SITEURL

When you configure WP_HOME and WP_SITEURL in your WordPress wp-config.php file, especially when they...

Recent Posts