background image

Content tagged with: drupal_set_breadcrumb

Eric'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);
  }
}
?>