Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This snippet adds <span class="breadcrumb-$number"></span>
to each breadcrumb link. This is useful if you have a fixed number of breadcrumbs on certain pages and wish to customize, say, the second breadcrumb link.
Paste this into your template.php file. Make sure to remove the php tags and to replace yourthemename with, you guessed it, your theme name.
function yourthemename_breadcrumb($breadcrumb) {
if (empty($breadcrumb)) {
return $themed_breadcrumb = '<div id="breadcrumb"></div>';
}
else {
$themed_breadcrumb = '<div id="breadcrumb">';
$array_size = count($breadcrumb);
$i = 0;
while ( $i < $array_size) {
$themed_breadcrumb .= '<span class="breadcrumb-';
$themed_breadcrumb .= $i;
$themed_breadcrumb .= '">' . $breadcrumb[$i] . '</span>';
if ( $i + 1 != $array_size ) {
$themed_breadcrumb .= ' >> ';
}
$i++;
}
$themed_breadcrumb .= '</div>';
return $themed_breadcrumb;
}
}
Comments
Thanks for this code
Thanks for getting me started with this. I need a first and last for my breadcrumbs. I modified the code to add a second class
If $1 is equal to 0 add my second class "first-crumb"
If $i + 1 is equal to the array count add second class "last-crumb"
I have it working on my system, but this is my first time sharing/modifying a snippet so please let me know if something is wrong with this version.
For Drupal 7
drupal 7 and omega
I was trying in my template.php in the subtheme and it didn't work. I solve it with css
I hope someone can use it :)
//trying to answer one question for each one that i make.
//this way, drupal will be more friendly and strong