Hi I want to change the code so that menu items on the current page use strong tags instead of llinks. I think its confusing to the user to have links on the current page.

Has anyone been able to do this?

Thanks
Steven

Comments

roborn’s picture

Override the theme_links() in your template.php, unset the href if the item active and replace span with strong.

Like this:

<?php

function phptemplate_links($links, $attributes = array('class' => 'links')) {
  $output = '';
  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';
    $num_links = count($links);
    $i = 1;
    foreach ($links as $key => $link) {
      $class = $key;
      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
        $class .= ' active';
        unset($link['href']); // unset href if the item is active
      }
      $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);
      } else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        // $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
        $output .= '<strong'. $span_attributes .'>'. $link['title'] .'</strong>';
      }
      $i++;
      $output .= "</li>\n";
    }
    $output .= '</ul>';
  }
  return $output;
}

?>

Roberto Ornelas | frontkom | Twitter: @roborn

stevenprice1974’s picture

Thanks I tried adding this to my theme, but it doesn't seem to do anything. Any advice?