Remove some menus in WordPress

by 5 replies
6
You can remove some menus of the WordPress interface by adding
the following code to the functions.php file of your theme:

PHP Code:
function remove_menu() {
global 
$menu;
unset(
$menu[2]); /* remove the menu "Dashboard" */
unset($menu[5]); /* remove the menu "Posts" */
unset($menu[10]); /* remove the menu "Medias" */
unset($menu[15]); /* remove the menu "Links" */
unset($menu[20]); /* remove the menu "Pages" */
unset($menu[25]); /* remove the menu "Comments" */
unset($menu[60]); /* remove the menu "Appearance" */
unset($menu[65]); /* remove the menu "Plugins" */
unset($menu[70]); /* remove the menu "Users" */
unset($menu[75]); /* remove the menu "Tools" */
unset($menu[80]); /* remove the menu "Settings" */
}

add_action('admin_head''remove_menu'); 
If you prefer to keep one of these menus, simply delete the
corresponding line of code.
#programming #menus #remove #wordpress
  • can we remove specific menus for specific roles?
    • [1] reply
    • Yes, like this:

      PHP Code:
      function remove_menu() {
      global 
      menu;
      if (!
      current_user_can('manage_options')) { unset(menu[25]); } /* remove the menu "Comments" if the user is not an admin */
      }

      add_action('admin_head''remove_menu'); 
      Add a $ just before menu.
  • Isn't it bad to use specific menu id-s? What if we add or remove menus from backend? You will still need to edit the actual php code then. Now very flexible...
  • WordPress developers won't change the numeric keys of the current menus.
  • Thank for this post it helps a lot

Next Topics on Trending Feed