Web Design that taps into the haromny and vision of your dreams.

Easy Wordpress Breadcrumb Trail

A simple copy and paste code to add breadcrumb trails to your WordPress pages

Written By on in PHP

240 words, estimated reading time 2 minutes.

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="breadcrumbs">
<?php
  if($title !== 'Browse') 
    echo $title;
  else 
    _e('Browse','options');
 
?>: <a href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>"><?php _e('Home','options'); ?></a> <?php echo $separator; ?>
<?php
 
  if(is_single()) :
    the_category(', '); echo ' ' . $separator . ' ';
  elseif(is_page()) :
    $parent_id = $post->post_parent;
    $parents = array();
    while($parent_id) :
      $page = get_page($parent_id);
      if($params["link_none"]) 
        $parents[] = get_the_title($page->ID);
      else 
        $parents[]  = '<a href="'.get_permalink($page->ID).'" title="'.get_the_title($page->ID).'">'.get_the_title($page->ID).'</a> ' . $separator . ' ';
      $parent_id  = $page->post_parent;
    endwhile;
 
    $parents = array_reverse($parents);
    foreach($parents as $val) :
      echo $val;
    endforeach;
  endif;
  the_title(); 
?>
  </div>
<?php
}

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

Last updated on: Wednesday 21st June 2017

 

Comments
curt

curt

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

Reply to curt
zachary smith

zachary smith

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

Reply to zachary smith

 

Leave a Reply

Your email address will not be published.





If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me