How to make a Drupal menu item link to itself for use with drop down menu modules.

A problem that I have always ran across when deploying Drupal sites is that there is no "out of the box" functionality that allows you to create a menu item that doesn't link.

A scenario to describe this problem is if you are using a menu module such as Superfish or Nice Menus. Lets say you have a top parent menu item, "Business Services", as shown in the image below:

Drupal Menu Parent Link

If you want to have the parent link (Business Services) dead, so that the user can't click on it, thus forcing the user to use the drop down menu, you are out of luck. This isn't possible with the core of Drupal. The path must contain either a path to an internal Drupal node, or an external link.

It seems logical to think that Drupal would allow a menu item to link to itself since we can link to external URL's. The way I used to work around this problem was to have the parent menu item (Business Services) be a page that simply listed the drop down menu items in a bulleted list. I found this redundant and searched for a different method.

I looked into a module, Menu Item Container to allow for this functionality, and also read a blog post about hacking the core includes/menu.inc file to disable the filter that checks the path input.

The Menu Item Container module was not available for Drupal 7 yet, and I did not want to hack Drupal core since it may affect future upgrades.

Since I couldn't have a menu item that didn't link, my next approach was to try to add a token into the path field of the menu item to make it link back to itself. I tried using "[current-page:url]/#" but Drupal rejected it because Tokens are not allowed in the path of menu items. After doing more research I found a module called Menu Token which allows you to use tokens in your path.

After downloading and installing Menu Token, I then added a new menu item called "Business Services". For the path I typed "[current-page:url]/#" and checked the box that says "Use tokens in title and in path.".

Drupal Menu Item Using Tokens

I then moved the children items to be underneath the new "Business Services" menu item, and deleted the old "Business Services" node that had the bulleted lists.

Drupal Menu List Using Tokens

The problem was solved.

I feel that Drupal should allow this functionality in the core; either by adopting the Menu Token module or by modifying the includes/menu.inc file. Feel free to leave a comment with your feedback or suggestions. I would love to hear how others have worked around this issue.

Share/Save

Comments

I too have been looking at how to do this. thanks!

this is super awesome. thanks!

That saved a bunch of time searching through modules - thanks!

Thanks a lot dear! It is really awesome. I was searching for this.

In D6 [current-page:url]/# should be [current-page-url]/# but it doesn't work. I installed Menu-Container which works great. Don't know why I tried your solution on D6 - what the heck, now that I did, here is the feedback.

Not as good as core functionality that simply supports "#" but this will do. Thanks!

This is great. I've been trying to make the special menu to work in my d7 installation but it didn't thanks to this.

Add new comment