background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount

Adding and removing links from the breadcrumbs

Eric.London's picture

This code snippet will show you how to search through the breadcrumbs and remove a particular item. Since I added this code to my theme in a preprocess_page function, I had to recreate $variables['breadcrumb']. NOTE: If I had chose to add this code to a module instead, I could have simply used the drupal_get_breadcrumb() and drupal_set_breadcrumb functions.

<?php
function MYTHEME_preprocess_page(&$variables) {
 
// in this example, I'm checking to see if icon_users.png exists in the breadcrumbs
 
if (stripos($variables['breadcrumb'],'icon_users.png')) {
   
// get the current breadcrumbs
   
$bc = drupal_get_breadcrumb();

   
// loop through the breadcrumbs
   
foreach ($bc as $k => $v) {
     
// check for a condition and remove as necessary
     
if (stripos($v,'icon_users.png')) unset($bc[$k]);
    }

   
// recreate the breadcrumbs using the theme_breadcrumb function
   
$variables['breadcrumb'] = theme('breadcrumb', $bc);
  }
}
?>

Newbie Question

Eric,

I am a newbie, so pardon the dumb question, but ...where is it exactly that I need to put this function?

Thanks

Eric.London's picture

template.php

Pardon me for not being more specific. You can add this function to your theme's template.php file. You'll have to replace "MYTHEME" in "MYTHEME_preprocess_page(&$variables)" with the name of your theme.

Regards,
Eric