Custom Breadcrumbs in Drupal

Category:

Aside from the handy dandy Custom Breadcrumbs module and/or using Views arguments to set your breadcrumb, sometimes you just want to set a breadcrumb programmatically on a certain url menu path with phptemplate_breadcrumb, here's how, right now:

function phptemplate_breadcrumb ($breadcrumb) {
  if ($_GET['q'] == 'my_custom/bread/and/butter/url/path') {
   $breadcrumb[] .= l('Bread', 'my-path-to/bread');
   $breadcrumb[] .= l('Butter', 'some-other-path-to/butter');
  }
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>';
  }
}

In the example above, when a user navigates to 'my_custom/bread/and/butter/url/path' the breadcrumb will get 'Bread' and 'Butter' appended to it. If you want to overwrite the breadcrumb instead of append to it, you'll first need to create an empty breadcrumb array. For example, $breadcrumb = array();

This code goes in your theme's template.php file because Ranger McFriendly said so.

Add new comment