I have a menu and would like to hide a specific item if the currently authenticated users doesn't have the "editor" role, which i created.

Since this is such a small thing, i would like to achieve that without the use of a 3rd party module.


This is not about security, I just want to hide the item regardless of the linked node's permission. In my specific case I'm even linking to a public node and just want to hide the menu item as long as the user hasn't the "editor" role.

  • How did you created menu? In drupal way or somthing else ? – Rupesh Mar 20 '14 at 9:56
  • 1
    @AnilSagar interesting! – n00b Mar 20 '14 at 10:03
  • 1
    @n00b If the path is a node, use the node access system (hook_node_access()). Menu links will automatically fall in line using that method – Clive Mar 20 '14 at 10:19
  • 1
    Okee dokee - I've removed the "user-permissions" tag to avoid confusion, as this isn't about permissions – Clive Mar 20 '14 at 10:29
  • 2
    @AnilSagar Nah, looks good to me - different use case from the usual 'how do I hide this link' question, so should be useful – Clive Mar 20 '14 at 11:15

Use hook_menu_item_link to alter menu items. See below example:

function mytheme_menu_item_link( $link ) {
  if( $link[ 'title' ] == 'My Account') {
    return '';
  • Or return NULL ;) – kwoxer Feb 10 '17 at 14:17

If security is not that important. This should kinda do the trick (untested code).

function YourTheme_menu_link(array $variables) {
  if ($variables['element']['#href'] == 'menu link to hide') {
    $variables['element']['#attributes']['class'][] = 'invisible';

 return theme_menu_link($variables);
  • Did not work for me. I needed to replace $variables['element']['#attributes']['class'][] = 'invisible' with return NULL; That works. – kwoxer Feb 10 '17 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.