Are you looking for a way to disable top-level menus from the admin panel? These snippets disable top-level menus, like the Comments menu, from the main menu in the admin panel.
Instructions:
Add one of the following snippets to your theme’s functions.php file or in a site-specific plugin:
- This snippet disables top-level menus using the menu ID. Menu IDs can be found in the
wp-admin/menu.php
WordPress file. Edit the menus IDs in lines 3 and 4, or add more similar lines, to change which menus are disabled.function remove_menu_items() { global $menu; unset($menu[15]); // Removes 'Links'. unset($menu[25]); // Removes 'Comments'. } add_action('admin_menu', 'remove_menu_items');
- This snippet disables top-level menus using the menu name instead of the menu ID. Edit the menus names in line 3, or add more array items, to change which menus are disabled.
function remove_menu_items() { global $menu; $restricted = array(__('Links'), __('Comments')); end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} } } add_action('admin_menu', 'remove_menu_items');
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: How to Install Google Analytics on Your WordPress Site.
Comments Leave a Reply