How to Disable Submenus from the WordPress Admin Panel

Home » Snippets » How to Disable Submenus from the WordPress Admin Panel
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

As a WordPress user, you may have found yourself wanting to restrict access to certain admin menu items or disable submenus altogether. This can be particularly useful in situations where you need to limit the capabilities of certain users or to prevent accidental changes to critical settings. In this article, we’ll cover several methods for disabling submenus from the admin panel in WordPress, from using code snippets to utilizing popular plugin solutions.

					function wpturbo_remove_submenus() {
    remove_submenu_page( 'themes.php', 'widgets.php' );
    remove_submenu_page( 'options-general.php', 'options-permalink.php' );
}
add_action( 'admin_menu', 'wpturbo_remove_submenus', 999 );
				

This code snippet allows you to remove specific submenus from the WordPress admin panel. The first line of the code block defines a new function called wpturbo_remove_submenus().

Inside the wpturbo_remove_submenus() function, we use the remove_submenu_page() function to remove the submenus that we want. In this case, we’re removing the ‘widgets’ submenu from the ‘Appearance’ menu and the ‘Permalinks’ submenu from the ‘Settings’ menu.

remove_submenu_page( 'themes.php', 'widgets.php' );
remove_submenu_page( 'options-general.php', 'options-permalink.php' );

The remove_submenu_page() function takes two parameters. The first parameter is the parent menu slug and the second parameter is the submenu slug that you want to remove.

We then use the add_action() function to hook the wpturbo_remove_submenus() function to the admin_menu action. The third parameter of add_action() sets the priority of the function. In this case, we’re setting it to 999 to ensure that it is executed last and has the final say on removing submenus.

Once you’ve added this code to your WordPress theme or plugin, the specified submenus will no longer be visible in the admin panel.

Register an account to save your snippets or go Pro to get more features.