4.6.x theme.inc theme_breadcrumb($breadcrumb)
4.7.x theme.inc theme_breadcrumb($breadcrumb)
5.x theme.inc theme_breadcrumb($breadcrumb)
6.x theme.inc theme_breadcrumb($breadcrumb)
7.x theme.inc theme_breadcrumb($variables)

Returns HTML for a breadcrumb trail.

Parameters

$variables: An associative array containing:

  • breadcrumb: An array containing the breadcrumb links.

Related topics

4 theme calls to theme_breadcrumb()
BlogTestCase::verifyBlogs in modules/blog/blog.test
Verify the logged in user has the desired access to the various blog nodes.
ForumTestCase::verifyForums in modules/forum/forum.test
Verifies that the logged in user has access to a forum nodes.
ForumTestCase::verifyForumView in modules/forum/forum.test
Verifies display of forum page.
template_process_page in includes/theme.inc
Process variables for page.tpl.php

File

includes/theme.inc, line 1898
The theme system, which controls the output of Drupal.

Code

function theme_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];

  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

    $output .= '<div class="breadcrumb">' . implode(' » ', $breadcrumb) . '</div>';
    return $output;
  }
}

Comments

akael’s picture

Here is something I needed to figure out, and thought I would share:

/* Put Breadcrumbs in a ul li structure */
function YOURTHEME_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];

  if (!empty($breadcrumb)) {
      $crumbs = '';
    }
  	return $crumbs;
  }
keti-1931’s picture

thanks.. it worked.

eternalistic’s picture

I needed a way to add a background image to work as a separator between the breadcrumbs rather than HTML characters so I came up with this using the above example as a starting point.

This allows you to have unique classes such as "breadcrumb-1" and "breadcrumb-2" so you can target the specific list items as well as a "first" and "last" class added to the list items.

Add this to your theme's template.php and theme as needed.

<?php
/**
 * Output breadcrumb as an unorderd list with unique and first/last classes
 */
function YOURTHEME_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];
  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
    $crumbs = '<ul class="breadcrumbs clearfix">';
    $array_size = count($breadcrumb);
    $i = 0;
    while ( $i < $array_size) {
      $crumbs .= '<li class="breadcrumb-' . $i;
      if ($i == 0) {
        $crumbs .= ' first';
      }
      if ($i+1 == $array_size) {
        $crumbs .= ' last';
      }
      $crumbs .=  '">' . $breadcrumb[$i] . '</li>';
      $i++;
    }
    $crumbs .= '</ul>';
    return $crumbs;
  }
}
?>
yellowhousedesign’s picture

Thanks for that - helped me out a lot for appending on the current note title. Here is my complete code:

	// Ouptuts site breadcrumbs with current page title appended onto trail
	function YOURTHEME_breadcrumb($variables) {
	  $breadcrumb = $variables['breadcrumb'];
	  if (!empty($breadcrumb)) {
	    // Provide a navigational heading to give context for breadcrumb links to
	    // screen-reader users. Make the heading invisible with .element-invisible.
	    $output = '

' . t('You are here') . '

'; $crumbs = ''; return $crumbs; } }
js’s picture

the <h2> is not being returned
needs something like
$output .= $crumbs;
return $output;

krisis’s picture

there's a typo in the code:

this line
$crumbs = '<div class="breadcrumb">';
should be
$crumbs .= '<div class="breadcrumb">';

That line, uncorrected, wipes the earlier assignment of the string and replaces it with the

IanNorton’s picture

Just to add to the above examples, I had a scenario where we were using page jumps as sub menu items, these caused a repeat in the menu, i.e.

Home > Features > Features,

I've added some code that stops this from happening, thought I'd share as may be useful for others, people will need to add in the first and last class code as before (not needed in our implementation)

function YOURTHEME_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];
  $breadcrumb = array_unique($breadcrumb);
    
  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '

' . t('You are here') . '

'; $crumbs = ''; return $crumbs; } }
darol100’s picture

I'm trying to translate this into D8. Do you have any idea on how to do this on Drupal 8 ?

hansrossel’s picture

Using a breadcrumb separator image

function MYTHEME_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];

  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '

' . t('You are here') . '

'; $breadcrumb_separator = '    '; $output .= ''; return $output; } }

and css:

.breadcrumb-separator {
  background:url(../images/separator-image.png) no-repeat center center;
}
BarisW’s picture

Add the following function to your theme to add the current page title to the breadcrumb:

function MYTHEME_breadcrumb($variables) {
  $variables['breadcrumb'][] = drupal_get_title();
  return theme_breadcrumb($variables);
}
harriska2’s picture

Where does the function (function MYTHEME_breadcrumb) get put? Into template.php?

cilestin’s picture

Correct, the MYTHEME_breadcrumb function gets put into template.php

luco’s picture

hey there,

maybe I'm in the wrong place to ask, but - how can I override the breadcrumb from a module, if the module functions are executed before the theme's?

any help is greatly appreciated.

Namari’s picture

+1

mark_fullmer’s picture

To set the breadcrumb in a module, you would need a hook_preprocess_page() function in your module that calls drupal_get_breadcrumb() and drupal_set_breadcrumb(). The first would allow you to examine what the default breadcrumb value is, and the second, to modify it. Example:

function mymodule_preprocess_page(&$variables) {
  if (some criteria to determine whether you want to modify) {
    _mymodule_breadcrumb(array('hello world'));
  }
}

function _mymodule_breadcrumb($breadcrumb) {
  $current = drupal_get_breadcrumb();
  $current = array_merge($current, $breadcrumb);
  drupal_set_breadcrumb($current);
}

The above would prepend "hello world" to the existing breadcrumb item.

tvb’s picture

+1

guusvandewal’s picture

function theme_breadcrumb($variables) {

  if (!empty($variables['breadcrumb'])) {
    $crumbs = "";
    $variables['breadcrumb'][] = '<span class="active">' . drupal_get_title() . '</span>';
    $breadcrumb = $variables['breadcrumb'];

    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

    $output .= theme('item_list', array(
      'items' => $breadcrumb,
      'type' => 'ul',
      'attributes' => array('id' => 'main-breadcrumbs', 'class' => array('breadcrumbs')),
        )
    );

    return $output;
  }
}
mbahlol’s picture

Dear all,

this is what i do with my template.php

  $breadcrumb = $variables['breadcrumb'];
  $crumbs ='';
  $title = $variables['breadcrumb'];
  $title[] = drupal_get_title();
  if (!empty($breadcrumb)) {
      $crumbs = '<ul id="breadcrumbs">';

      foreach($breadcrumb as $value) {
           $crumbs .= '<li>'.$value.'</li>';
      }
      $crumbs .= '<li>'.drupal_get_title().'</li></ul>';
    }
      return $crumbs;

it show double title in my poll result http://web.pn-pontianak.go.id/node/55/results but other page just print one title.

please let me know if anything wrong with that code

regards

mbahlol

dstorozhuk’s picture


function theme_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];
  if (!empty($breadcrumb)) {
    $show_home = theme_get_setting('show_home');
    if (!$show_home && $breadcrumb[0] == l(t('Home'), '')) {
      array_shift($breadcrumb);
    }
    $count = count($breadcrumb) - 1;
    $items = array();
    foreach($breadcrumb as $key => $value) {
      if($count != $key) {
        $d = filter_xss(theme_get_setting('breadcrumb_delimiter'));
        $items[] = $value . '' . (empty($d) ? '/' : $d) . '';
      }else{
        $items[] = $value;
      }
    }
    $return = array(
      '#theme' => 'item_list',
      '#items' => $items
    );
    return drupal_render($return);
  }
}

jmm42’s picture

Using various codes from above, I compiled the following:


function MYTHEME_breadcrumb($variables) { 
  $breadcrumb = $variables['breadcrumb'];
  $crumb_arrow = ' &raquo ';
 
  if (!empty($breadcrumb)) {
	$arr_crumbs = array();
	array_push($arr_crumbs, '' . implode($crumb_arrow, $breadcrumb) . '');
	
	$output = '

' . t('You are here') . '

'; $array_size = count($arr_crumbs); for ($i=0; $i Edit Page') { $current_crumb = 'Edit'; } $output .= $arr_crumbs[$i] . '' . $crumb_arrow . $current_crumb . ''; break; } $output .= $arr_crumbs[$i]; } return ''; } }
aayesha’s picture

Hello guys;
$variables taken as argument, can anybody explain me this array?

cfbauer’s picture

If you're using bootstrap and getting an array to string conversion error, you'll need to use their version:

function local_breadcrumb($variables) {
  // Use the Path Breadcrumbs theme function if it should be used instead.
  if (_bootstrap_use_path_breadcrumbs()) {
    return path_breadcrumbs_breadcrumb($variables);
  }

  $output = '';
  $breadcrumb = $variables['breadcrumb'];

  // Determine if we are to display the breadcrumb.
  $bootstrap_breadcrumb = bootstrap_setting('breadcrumb');
  if (($bootstrap_breadcrumb == 1 || ($bootstrap_breadcrumb == 2 && arg(0) == 'admin')) && !empty($breadcrumb)) {
    $output = theme('item_list', array(
      'attributes' => array(
        'class' => array('breadcrumb container'),
      ),
      'items' => $breadcrumb,
      'type' => 'ol',
    ));
  }
  return $output;
}
fweiss’s picture

Thx cfbauer, that worked perfectly for me.