How to hide menu item from high level roles but show for low level I have 3 roles on site:


anonymous user
authenticated user
admin


I created a new page:

function learning_menu()
{
    $items = array();

    $items['learning'] = array(
        'page callback'    =&gt; 'learning_output',
        'access callback' =&gt; 'learning_access',
        'type' =&gt; MENU_CALLBACK,
        );

    return $items;
}


I manually created a menu item for this page in the top menu. This item should be displayed only for authenticated users, but not admins. Unfortunately, admin as also an authenticated user. So I had to use a trick to disallow access to this page to admins using this access callback:

function learning_access()
{
    global $user;

    $n = count($user-&gt;roles);
    if ($n === 1)
    {
        $data = array_values($user-&gt;roles);
        if ($data[0] === 'authenticated user')
        {
            return true;
        }
    }

    return false;
}


It works but when I uploaded this module to server, I was unable to manually add a menu item for this page. Because admin doesn't have access to it.

How can I allow an admin to access this page? In the same time the menu item shouldn't be shown for him.
As per the discussion above,

Remove 'access callback' =&gt; 'learning_access', add drupal_access_denied() in page call back

function learning_menu() {
  $items = array();

  $items['learning'] = array(
    'page callback' =&gt; 'learning_output',
    'type' =&gt; MENU_CALLBACK,
  );

  return $items;
}



function learning_output() {
  global $user;

  $n = count($user-&gt;roles);
  if ($n === 1) {
    $data = array_values($user-&gt;roles);
    if ($data[0] === 'authenticated user') {
      drupal_access_denied();
    } else {
      //YOUR code Here      
    }
  }
}


And Use Roles for Menu module to hide the learning menu.


  This module allows you to restrict access to menu items based on user
  roles. It is used when you don't want to copy your whole menu just
  because for one specific role you want to hide one menu item.
  
  The module will add a fieldset with options for restricting access or
  gaining access to menu link for a specific role/roles