Skip to main content

Allowing HTML in Drupal menu items

An article from ComputerMinds - Building with Drupal in the UK since 2005
16th Dec 2007

Mike Dixon

Senior Mind
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

You have to be a little careful with this one, but there are many times when in would be very handy to have HTML in your Drupal menu items. For example, you might want your Drupal menu to have a <br> to force a break, or perhaps insert a <span> around some content to get a two-tone menu item

Add the following to your Drupal theme's template.php file


function phptemplate_menu_item_link($item, $link_item) {
    $output = l($item['title'], 
                $link_item['path'],
                array(), 
                null, 
                null, 
                false, 
                true);    
}

By setting the final paramater on the l function to true, we are telling Drupal that the menu item should be treated as HTML. NOTE this obviously means all your menu items will now not be filtered, so probably best not to use this on a site where punters can add menu items!

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.