Customizing Primary links in Drupal

This Post will explain you ” How To change Primary Link in Drupal”. Here i am explaining two methods by which you can change your primary link.

Add Span in Primary Links:

Method 1: Overriding the theme_preprocess_page() function in your theme template file

function  MYTHEME_preprocess_page(&$vars) {
$links =  $vars['primary_links'];
foreach  ($links as $key => $link) {
 $links[$key]['html']  = true;
 $links[$key]['title']  = '<span>'. $link['title'] . '</span>';
 }

 $vars['primary_links']  = $links;
}

Method 2: Overriding the theme_links() function in your theme template file

function  MYTHEME_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';
 }

 $output .=  '<li'. drupal_attributes(array('class' => $class)) .'>';

 // wrap  <span>'s around the anchor text
 if  (isset($link['href'])) {
 $link['title']  = '<span>' . check_plain($link['title']) . '</span>';
 $link['html']  = TRUE;
 // 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>';
 }

 $i++;
 $output .=  "
</li>
\n";
 }

 $output .= '
</ul>
';
 }
 return $output;
}