Managing the WordPress dashboard effectively is essential for a seamless experience, especially when certain plugins add unwanted menu items. By using the functions remove_menu_page()
and remove_submenu_page()
in the functions.php
file, you can control which menus appear in the admin panel. Here’s how to do it.
Disable Top-Level Menus Added by Plugins
If a plugin adds a top-level menu item to the sidebar, you can remove it with the remove_menu_page() function. For instance, if a plugin has created a menu item named “WP Mail SMTP,” you can use its menu slug to remove it as shown below:
add_action('admin_menu', function() {
remove_menu_page('wp-mail-smtp'); // Use the actual slug of the menu
});
Disable Submenus Added by Plugins
Similarly, if a plugin has added a submenu, you can use remove_submenu_page() to remove it. For example, to remove a submenu under the “Settings” menu, you would do the following:
add_action('admin_menu', function() {
remove_submenu_page('options-general.php', 'wp-mail-smtp'); // 'options-general.php' is the slug for the "Settings" menu
});
How to Find the Menu Slug
To identify the menu or submenu slug for a plugin, you can use one of the following methods:
Developer Tools: Open the browser’s developer tools (F12) and inspect the menu item to find its link. Typically, the last part of the URL is the menu slug. For example, if you see a URL like
example.com/wp-admin/admin.php?page=wp-mail-smtp
, thenwp-mail-smtp
is the slug.Check the Plugin Code: If the plugin documentation does not specify the menu slug, examine the plugin’s source code, searching for
add_menu_page()
oradd_submenu_page()
function calls to locate the slug.
Example of Disabling Multiple Plugin Menus
If you wish to disable the menus of multiple plugins simultaneously, you can list their slugs as follows:
add_action('admin_menu', function() {
// Disable multiple top-level menus
remove_menu_page('wp-mail-smtp');
remove_menu_page('another-plugin-slug');
// Disable multiple submenus
remove_submenu_page('options-general.php', 'wp-mail-smtp');
remove_submenu_page('tools.php', 'another-plugin-submenu');
});
Understanding Menu Slugs
In WordPress, a menu slug is the unique identifier used by plugins or pages in the admin interface, generally a string. It functions as part of the URL to mark specific pages or functionalities in the dashboard. The slug is neither the menu name nor completely the URL—it is a segment of the URL, often used to uniquely identify a menu item.
Relationship Between Menu Slugs and URLs
The menu slug typically appears in the URL string as follows:
When you click a plugin menu item, the URL might look like this: https://example.com/wp-admin/admin.php?page=wp-mail-smtp
. Here, wp-mail-smtp
is the menu slug.
Finding the Menu Slug
There are several ways to identify a menu slug:
Using Browser Developer Tools: Navigate to the WordPress admin and find the desired menu. Right-click and choose “Inspect.” Locate the
href
attribute of the menu link, which will generally look likeadmin.php?page=wp-mail-smtp
. The part afterpage=
is the slug.Direct URL Checking: Click the admin menu item and view the URL in the browser’s address bar. It frequently appears as
https://example.com/wp-admin/admin.php?page=plugin-slug
, where the part afterpage=
is the slug.Examining Plugin Source Code: In some cases, examining the plugin code may be necessary, as the menu is added through
add_menu_page()
oradd_submenu_page()
; the slug is an argument in these function calls.
Troubleshooting Why Some Methods Don’t Work
If your attempts to remove a menu do not work, consider these factors:
- Timing of Menu Item Loading: Some plugins may load their menu items after the
admin_menu
hook, making the remove_menu_page() ineffective. Use theadmin_init
hook or adjust the priority of theadmin_menu
hook to ensure removal actions execute after menus load.
add_action('admin_menu', function() {
remove_menu_page('stk-custom-fields');
remove_menu_page('wpforms-overview');
remove_menu_page('elementskit');
remove_menu_page('wp-mail-smtp');
}, 99); // Increase priority
Menu Item Registration Position: Some plugins may register their menu items as submenus rather than top-level menus. Thus, you need to use remove_submenu_page() to disable these. Check the plugin code or use browser developer tools to examine the menu structure.
Confirming Menu Slug: Even after checking, it’s advisable to verify the slug again. Inspect the
href
attribute in the browser developer tools for the exact slug.
By following these steps, you can effectively troubleshoot and manage menu visibility in your WordPress dashboard customizing your admin experience to fit your needs.
By implementing these methods, you can achieve a customized WordPress dashboard that aligns with your specific requirements while enhancing usability and organization. For further improvements in your WordPress experience, consider exploring other customization techniques.