Is there a way to hide menu links on the main menu based on the URL?

For instance, if my URL is 'example.com/undergraduate', the main menu links would be different than if I were to go to 'example.com/graduate'.

This obviously can't be too hard? A module would be awesome.

  • You can use drupal.org/project/path_access and prevent link path to be accessed (I think it checks access to the path before rendering menu link)
    – Ales
    Commented Jul 14, 2020 at 7:17

1 Answer 1


If you want to have page specific menu system, you can create different menu blocks and put them appropriately.

Considering your example

Main menu is nothing but a menu block, so instead of using main menu block you can have two different menu blocks let say Menu block A and Menu block B

So in block configuration for Menu block A you will put the block visibility to show on "undergraduate" only and similarly put for Menu block b put it as "graduate"

Remember to put the menu blocks in same region as your main menu. You are just toggling menu block visibility on basis of URL.

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.