I have users who are the owners of some nodes, and each node has a menu link in the main menu. Users can only see the nodes they own, and they cannot see other user's nodes.

The problem now is that the menu is displayed like in the following image, for all the users; it shows links for both the nodes owned by the current user, and the nodes the current user doesn't own.


I would like to display only the menu items corresponding to the nodes owned by the logged in user. How can I do this?

3 Answers 3


Drupal will hide menu items for paths that users don't have access to. But for this to work, it requires that the access callback for that menu item returns FALSE. If you handle access control in the menu callback instead, Drupal won't know that the user doesn't have access and will display the menu.

A solution would be to implement a custom access control module/function if you can't use any of the existing for the nodes.

  • Actually I use hook_node_access to handle the permissions to nodes. But how can I control the menu display to depend on the node if is accessible for user or not? Can I do this in the same hook as for node access, hook_node_access ?
    – EKK
    Commented Mar 30, 2011 at 8:58

For each menu entry you want to control access to I assume you have a hook_menu (http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_menu/7) array value setup? The property that you're interested in for each of these array entries is "access callback" - a function returning TRUE if the user has access rights to this menu item, and FALSE if not.

Use user_access($string, $account = NULL) (http://api.drupal.org/api/drupal/modules--user--user.module/function/user_access) with a target access permissions value of your choosing based on this reference: (http://drupal.org/node/132202)


You may find the following answers (that give modules to do this functionality) in...

How can I show/hide just one menu item based on user role?


Drupal menu_per_role module:


Drupal Menu Item Visibility.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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