Add attributes to Drupal breadcrumb links.

If you for any reason would like to add attributes to your breadcrumb links, this is how i did it; instead of

print $breadcrumb;

i did

print str_replace('">', '" target="_top">', $breadcrumb);

I needed this because i created a template with frames for external links. The top of the frame uses the standard "header" region, the bottom uses an external link. This snippet makes sure that when i click on a breadcrumb link, it will open in the "_top". You could use this to add any odd attribute though. I welcome cleaner methods, this worked for me though. It took me a while to figure this out so i thought i'd share.

Perhaps a Better Way

more "clean" way is to override theme function in template.php, insted of making breadcrumb changes in page.tpl.php

example: (template.php)

function mytheme_breadcrumb($breadcrumb) {
  $sep = ' > ';
  if (count($breadcrumb) > 0) {
    return implode($breadcrumb, $sep) . $sep;
  }
  else {
    return t("Home");
  }
}

or other example: (template.php)

function phptemplate_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' » ', $breadcrumb) .'</div>';
  }
}

more info: http://drupal.org/node/64067

 
 

Drupal is a registered trademark of Dries Buytaert.