How to Easily Disable Top Level Menus from the WordPress Admin Panel

Home » Snippets » How to Easily Disable Top Level Menus 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 website owner or developer, you might want to limit the access of certain users to the WordPress admin panel, especially when it comes to the top-level menus. By disabling the top-level menus, you can control what users can see and access in the admin panel, making it easier for them to navigate and reducing the risk of accidental edits or changes. In this article, I’ll show you how to disable top-level menus from the admin panel in WordPress, giving you greater control and customization options for your website.

					function wpturbo_remove_menus() {

    //remove top level menus
    remove_menu_page( 'index.php' );                  //Dashboard
    remove_menu_page( 'edit.php' );                   //Posts
    remove_menu_page( 'upload.php' );                 //Media
    remove_menu_page( 'edit.php?post_type=page' );    //Pages
    remove_menu_page( 'edit-comments.php' );          //Comments
    remove_menu_page( 'themes.php' );                 //Appearance
    remove_menu_page( 'plugins.php' );                //Plugins
    remove_menu_page( 'users.php' );                  //Users
    remove_menu_page( 'tools.php' );                  //Tools
    remove_menu_page( 'options-general.php' );        //Settings

}
add_action( 'admin_menu', 'wpturbo_remove_menus' );
				

In this section, we will explain the code snippet that can be used to disable top-level menus from the WordPress admin panel.

The code creates a new function called wpturbo_remove_menus(). This function will be responsible for removing the top-level menus from the WordPress admin panel.

To remove the menus, we use the remove_menu_page() function. This function takes the slug of the menu to be removed as its argument. As you can see in the code snippet, we have passed the slugs of various top-level menu items that are to be removed.

For example, to remove the Dashboard menu item, we use the following line of code:

remove_menu_page( 'index.php' ); //Dashboard

Similarly, we remove other top-level menu items like Posts, Media, Pages, Comments, Appearance, Plugins, Users, Tools, and Settings.

We then use the add_action() function to hook our wpturbo_remove_menus() function into the admin_menu action. This ensures that the function is executed when WordPress generates its admin menu.

Once implemented, the top-level menus that we specified will be removed from the WordPress admin panel. It is essential to note that this code snippet only removes the top-level menus and cannot be used to remove submenus.

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