Last updated April 26, 2011. Created by arshadcn on March 15, 2010.
Edited by zilverdistel, NimbyDagda, philbar, pmonjo. Log in to edit this page.

This little code snippet will add the present page title to the breadcrumb. We show you how to use this in steps.

Step 1 : If you do not have a template.php file in your sites/all/themes/yourtheme/ folder, create one.

Step 2 : Copy and paste this code in the template.php file.

<?php
function MYTHEME_breadcrumb($breadcrumb){
     if (!empty(
$breadcrumb)) {
       
$breadcrumb[] = drupal_get_title();
        return
'<div class="breadcrumb">'. implode(' » ', $breadcrumb) .'</div>';
    }
}
?>

for Drupal 7 the function should be.

<?php
function MYTHEME_breadcrumb($variables) {
 
$breadcrumb = $variables['breadcrumb'];
  if (!empty(
$breadcrumb)) {
   
// Adding the title of the current page to the breadcrumb.
   
$breadcrumb[] = drupal_get_title();
   
// 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;
  }
}
?>

That's it. Clear your cache. The current node title should now be displayed in the breadcrumb.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

doesn't work on drupal 7. only title is printed

looks something like this

array » Obama wins election

plus, 'phptemplate' should be replaced with 'MYTHEME' -- 'MYTHEME' should be the name of your theme folder...

(not everyone is going to know this offhand )

hence it would be helpful to most for drupal 5 & 6 versions if it looked like this:

<?php
function MYTHEME_breadcrumb($breadcrumb){
     if (!empty(
$breadcrumb)) {
       
$breadcrumb[] = drupal_get_title();
        return
'<div class="breadcrumb">'. implode(' » ', $breadcrumb) .'</div>';
    }
}
?>

replace in page.tpl.php this

    <?php if ($breadcrumb): ?>
      <div id="breadcrumb"><?php print $breadcrumb; ?></div>
    <?php endif; ?>

with this ..
<?php if ($breadcrumb): ?>
      <div id="breadcrumb">
  <?php
      $temp
= "</a> &raquo; <a href="">" . $title . "</a></div>";
     
$breadcrumb = str_replace("</a></div>", $temp, $breadcrumb);
      print(
$breadcrumb);
     
?>

  </div>
    <?php endif; ?>

I use

<?php
return '<div class="breadcrumb">'. implode(' &#187; ', $breadcrumb) .'</div>';
?>

instead
<?php
return '<div class="breadcrumb">'. implode(' » ', $breadcrumb) .'</div>';
?>

to show separator correctly

I needed my breadcrumbs to display as an inline list. This allows for the list, and CSS gives me the inline display.

<?php
function MYTHEME_breadcrumb($breadcrumb){
     if (!empty(
$breadcrumb)) {
       
$breadcrumb[] = drupal_get_title();
        return
'<div class="breadcrumb"><ul><li>'. implode('</li><li>', $breadcrumb) .'</li></ul></div>';
    }
}
?>

When using ZEN go to: appearance > [your theme] > settings and under the title ‘Breadcrumb settings’. you can turn this on with a checkbox.

If you don't want to use ZEN it still might be worth having a look at how they did it.

Hi everyone, I'm not a php expert I'm only trying to insert a breadcrumb like HOME>SECTION1>PAGE on my "views pages" but I don't know what to do...

Actually the breadcrumb appears correctly on the other pages but not on "view pages", on view pages appears only "SECTION1" and not HOME>SECTION1>PAGE

Please help me
Thaks
Francky

Webdesign | Soundesign | http://www.francescogiannico.com