Add custom breadcrum

I have to add a custom breadcrumb to my twitter page (Share >> Members >> User >> Recent tweets) . for this we need to add a the following code in templete.php. We will user your_theme_preprocess_breadcrumb() function.

function your_theme_preprocess_breadcrumb(&$variables) {
// Replace the default search api breadcrumb.
foreach ($variables['breadcrumb'] as $key => $breadcrumb) {
  $strip_breadcrumb = strip_tags($breadcrumb);
if ($strip_breadcrumb == '[all items]') {
  $variables['breadcrumb'][$key] = t('All Content');
}
}
if ((arg(0) == "user") && (is_numeric(arg(1)))) {
  $user = profile2_load_by_user(arg(1));
  $user_name = $user['main']->field_ekn_name['und'][0]['value'];
  $user_uid = $user['main']->uid;
  //echo ""; print_r($user_uid);
  //echo ""; print_r($user);die();
  $variables['breadcrumb'][1] = l('Share', 'share');
  $variables['breadcrumb'][2] = l('Members', 'share/members');
  $variables['breadcrumb'][3] = t($user_name);
if ((arg(0) == "user") && (is_numeric(arg(1))) && arg(2) == 'tweets') {
  $variables['breadcrumb'][3] = l(t($user_name),'share/members/' .$user_uid);
  $variables['breadcrumb'][4] = t('Recent Tweets');
  }
 } 
}
Advertisements

Overriding the breadcrumb

An easy way to Override the breadcrumb to use hook_breadcrumb in templete.php. In my profile page the user profile name was missing only “home” was getting displayed. i used to following code in templete.php :

function YOUR_THEME_NAME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if(arg(0) == "user") {
$breadcrumb[]= drupal_get_title();
$output = '
</code>
<div class="breadcrumb">' . implode('>>', $breadcrumb) . '</div>
';
return $output;
}
}

One more way is : create a breadcrumb.tpl.php file in your theme folder and add following line:
This will only change the default symbol( >>) between breadcrumb string to !.