Learning never exhausts the mind
Home >  Web Design > WordPress > Easy WordPress Breadcrumb Trail

Published 24th January 2009 by

This is a great function which you can use to output a breadcrumb trail navigation links on your blog.

I did not write this function, but its one of the ones in my global functions.php which is used on most of my sites. I cannot remember where I got it from or who wrote it.

function breadcrumbTrail($crumbs = true, $title = 'Browse', $separator = '/') 
  global $post;
  <div class=&quot;breadcrumbs&quot;&gt;
  if($title !== 'Browse') 
    echo $title;
?&gt;: &lt;a href=&quot;&lt;?php bloginfo('url'); ?&gt;&quot; title=&quot;&lt;?php bloginfo('name'); ?&gt;&quot;&gt;&lt;?php _e('Home','options'); ?&gt;&lt;/a&gt; &lt;?php echo $separator; ?&gt;
  if(is_single()) :
    the_category(', '); echo ' ' . $separator . ' ';
  elseif(is_page()) :
    $parent_id = $post-&gt;post_parent;
    $parents = array();
    while($parent_id) :
      $page = get_page($parent_id);
        $parents[] = get_the_title($page-&gt;ID);
        $parents[]  = '&lt;a href=&quot;'.get_permalink($page-&gt;ID).'&quot; title=&quot;'.get_the_title($page-&gt;ID).'&quot;&gt;'.get_the_title($page-&gt;ID).'&lt;/a&gt; ' . $separator . ' ';
      $parent_id  = $page-&gt;post_parent;
    $parents = array_reverse($parents);
    foreach($parents as $val) :
      echo $val;

To use this function simply make a call to breadcrumbTrail() in the template where you wish to show the breadcrumbs.

2 thoughts on “Easy WordPress Breadcrumb Trail
  • curt
    20th November 2009 at 12:00 am

    Great Work! I've just looking for this code. Only pages breadcrumb trails functionality. BreadcrumbXT doesn't help me in my case.

  • zachary smith
    29th October 2009 at 12:00 am

    YES! This works perfectly! I just just yelled 'YES' a few times and did a celebratory walk around my apartment.


Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.