Using Html in Drupal Menu Title Fields

I was recently working on a project that required superscripted ®, ™, and SM to be added to some menu items. Unfortunately, Drupal does not make it easy to put html in certain fields such as node title or menu title. Html will generally get filtered and removed before a page renders. While researching a way to add html tags to menu link titles, I came across the html_menu project which allows one to add markup to menu title fields. I didn't like the idea of adding yet another module to an already large Drupal install so I dug around in the module to see how they were doing it. Not surprisingly Drupal has a hook that gives developers the ability to alter the link array and set the ['options']['html'] key to 1. So instead of adding an entire module to enable this feature you can add the following snippet to a custom module or your theme's template.php file.

/** * Implements hook_menu_link_alter(). */ function custom_menu_link_alter(&$item) { $item['options']['html'] = 1; }

After implementing this, however, it did not seem to work so after reading this hook's documentation I discovered that this hook is only called after a menu item is saved. I then went to the menu in question disabled the links and reenabled them which did the trick.

Tags: Drupal 7