I have set up a menu with a list of menu titles which is working fine. But as I want to style the link li with a background-color and rounded corners, I need to be able to manually insert a break in longer length menu titles, rather than rely on the width controlling the line break automatically.

From what I've been able to glean from searching online, there is some way to do this by modifying a copy of a template file from core into my theme, but I'm not sure how to do this or if there is a simpler way.

Using Drupal 7.


1 Answer 1


You need to override theme_menu_link(), so in your template.php file from your theme put this code:

function MYTHEME_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);

  //Split titles using a <br /> when longer than 20 characters
  $element['#title'] = wordwrap($element['#title'], 20, "<br />");
  //Set HTML to TRUE to display properly the HTML
  $element['#localized_options']['html'] = TRUE;

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";

Change MYTHEME by your theme name.
I used wordwrap() to split long menu title in small chunks but you can implement your own logic there.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.