Warning: Table './schoonz_drupal7/watchdog' is marked as crashed and last (automatic?) repair failed query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";N;s:8:\"%message\";s:30:\"Function split() is deprecated\";s:5:\"%file\";s:63:\"/home/schoonz/public_html/sites/all/themes/zen/zen/template.php\";s:5:\"%line\";i:132;}', 3, '', 'http://www.schoonzie.com/introducing-the-menu-attributes-module', '', '', 1414306499) in /home/schoonz/public_html/includes/database.mysql.inc on line 128
Introducing the Menu Attributes module | Schoonzie

Introducing the Menu Attributes module


Over the Christmas break I decided that I’d had enough of hard coding theme functions to add attributes to specific menu items in Drupal, so I finally took the time to write a module that would do the heavy lifting. The outcome is the Menu Attributes module.

All the module does is give you the ability to add attributes to the menu item <a> elements, but this has been something I've wanted in Drupal for a long time now.

The main reason I wrote the module was to add the rel="nofollow" attribute to certain menu items (learn why you should be using nofollow to direct PageRank to high value pages), but it made sense to allow users to set other valid attributes as well. So far I have included the Id, Name, Target, Rel, Class, Style, and Accesskey attributes which can be added to any menu item. If you think other attributes would be useful, let me know I’m happy to consider including them.

In the next couple of weeks or so I’ll be releasing an update to include an admin page so that you can choose which attributes are available on the menu form so as not to overcrowd the form with items that you’ll never use.

It’s worth noting that the actual attributes are stored in the menu_links table in the options field of the menu item itself so no new databases are needed and no additional processing done when building the menu. The one drawback of this is that there is no way to mass reset the attributes you’ve set using the module, because it is stored alongside other attributes that are set by other modules.

If you’ve got any other uses or feedback for the module, I’d love to hear them in the comments.