I'm trying to remove line breaks from the list generated by my primary links, ie I want to change this:

<li>Apples</li>
<li>Pears</li>
<li>Bananas</li>

to this:

<li>Apples</li><li>Pears</li><li>Bananas</li>

This is to sort out some CSS problems I'm having in displaying a horizontal list without gaps between the items.

I've tried removing the new line character from theme_menu_item but this only seems to change my other menus - not the primary links.

Grateful for suggestions.

Comments

Rob L’s picture

Should have mentioned this is using Drupal 6, if that makes a difference.

ainigma32’s picture

That way you can see what theme function or template you can override to remove the linebreaks.

- Arie

oksid’s picture

Try to find all /li in /includes/theme.inc and /includes/menu.inc and if there is \n after </li> remove it.

Remove them all to get sure ;)

exp:

before :
$output .= ' <li>'. $message ."</li>\n";

after:
$output .= ' <li>'. $message ."</li>";

oksid’s picture

I found this solution, it removes all line breaks after <li></li>
put this code into your template.php (remove the <?php ?>)

function mythemename_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty($extra_class)) {
    $class .= ' ' . $extra_class;
  }
  if ($in_active_trail) {
    $class .= ' active-trail';
  }
  return '<li class="' . $class . '">' . $link . $menu . "</li>";
}