Using WordPress ‘remove_submenu_page()’ PHP function

The remove_submenu_page() WordPress PHP function removes a specified submenu item from the admin dashboard.

Usage

A generic example of how to use the function:

remove_submenu_page('parent_menu_slug', 'submenu_slug');

Parameters

  • $menu_slug (string, required) – The slug for the parent menu.
  • $submenu_slug (string, required) – The slug of the submenu.

More information

See WordPress Developer Resources: remove_submenu_page

Examples

Remove the Widgets submenu page

This example removes the Widgets submenu page from the Appearance menu:

function remove_widgets_submenu() {
    remove_submenu_page('themes.php', 'widgets.php');
}
add_action('admin_menu', 'remove_widgets_submenu', 999);

Remove the Plugin Editor submenu

This example removes the Plugin Editor submenu from the Plugins menu:

function remove_plugin_editor_submenu() {
    remove_submenu_page('plugins.php', 'plugin-editor.php');
}
add_action('admin_menu', 'remove_plugin_editor_submenu', 999);

Remove the Import submenu from the Tools menu

This example removes the Import submenu from the Tools menu:

function remove_import_submenu() {
    remove_submenu_page('tools.php', 'import.php');
}
add_action('admin_menu', 'remove_import_submenu', 999);

Remove the Add New submenu from the Posts menu

This example removes the Add New submenu from the Posts menu:

function remove_add_new_post_submenu() {
    remove_submenu_page('edit.php', 'post-new.php');
}
add_action('admin_menu', 'remove_add_new_post_submenu', 999);

Remove the Add New submenu from the Pages menu

This example removes the Add New submenu from the Pages menu:

function remove_add_new_page_submenu() {
    remove_submenu_page('edit.php?post_type=page', 'post-new.php?post_type=page');
}
add_action('admin_menu', 'remove_add_new_page_submenu', 999);