Adding Line Breaks to menu items in Drupal 7

Public

Add this function to your theme's template.php file to get line breaks working in your menu items:

Get raw version
php
  1. /**
  2. * Override theme_menu_link() to add line breaks in menu items
  3. * that have a <br> or <br/> or <br /> placed in them.
  4. */
  5. function YOURTHEME_menu_link(array $variables) {
  6. $element = $variables['element'];
  7. $sub_menu = '';
  8.  
  9. if ($element['#below']) {
  10. $sub_menu = drupal_render($element['#below']);
  11. }
  12. $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  13.  
  14. // Replace text line breaks with html line breaks.
  15. $output = str_replace("&lt;br&gt;", "<br/>", $output);
  16. $output = str_replace("&lt;br/&gt;", "<br/>", $output);
  17. $output = str_replace("&lt;br /&gt;", "<br/>", $output);
  18.  
  19. return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
  20. }