Last updated August 23, 2009. Created by dagomar on March 27, 2008.
Edited by lisarex, bekasu. Log in to edit this page.

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

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Hello,
This is how you added attributes, but what if you want to delete some ? I'm wondering how could I get rid of the attribute title in the of the the breadcrumb ?

D.

David THOMAS
http://www.smol.org

Re-hello,
I didn't find the drupal way, but did it the "PHP way"...
I was trying to remove the "title" attribute, but this solution can be used for any attribute.

In template.php I added in my function MYTHEME_breadcrumb() like this:

<?php
function MYTHEME_breadcrumb($variables) {
 
$breadcrumb = $variables['breadcrumb'];
 
//pattern to find all title="anything-inside-double-quote"
 
$pattern = "#title="(.+)?"#";
  foreach(
$breadcrumb as $k => $value){
       
//replace with nothing so title won't print
      
$breadcrumb[$k] = preg_replace($pattern, '', $value);
  }
   
//...some other code...
   
$output .= '<div class="breadcrumb">' . implode(' » ', $breadcrumb) . '</div>';
    return
$output;
  }
}
?>

Thanks to regex ;-)
It took me some time, but nothing too long for accessibility...

Cheers.

David THOMAS
http://www.smol.org