← Back to postsDrupal 7 - Custom Breadcrumbs with PHP

Drupal 7 - Custom Breadcrumbs with PHP

Published: 10/23/2015

I have a content type called Features. This content type contains multiple subcategories of data, including News Releases, Awards, Informative Tips, and Patient Stories. This subcategory is a field on the content type, and is chosen when a Feature node is created. Because data pertains to different subcategories, I preferred to have the sub-category in the breadcrumb string. Below is how I accomplished this.

  1. Created the Content Type and all required fields.
  2. On the Edit Tab of the Content Type, checked the option 'Display defined custom breadcrumbs on node edit form'
  3. Navigated to admin/structure/custom_breadcrumbs
  4. On the Node tab, added a new breadcrumb, gave it a name of 'News Item' and associated it with the Node type of 'Features'.
  5. For Breadcrumb visibility, added the following PHP code:

if ($node->field_article_type['und'][0]['value'] == 'newsrelease') return TRUE;

  1. For Titles, added the display title of the breadcrumb, in this case 'News'
  2. For Path, entered the real path of the parent page. In this case, I wanted the parent breadcrumb to go to http://domain/newsroom (opens in new tab). So the path is simply 'newsroom'
  3. Repeated for the additional subcategories, using the machine name of the subcategory for each PHP statement

Below is a screen shot of my setup for News Releases: