How to: Breadcrumb function for Wordpress
Posted by Jean-Baptiste Jung on Jun 20, 2008 in WordPress • 25 commentsUnfortunely, Wordpress doesn’t have a default function to display a breadcrumb. We’ll see how to create this navigation technique, and display it on our posts, pages and categories archives.
Breadcrumb...What's that?!?
Wikipedia says:
Breadcrumbs or breadcrumb trail are a navigation technique used in user interfaces. Its purpose is to give users a way to keep track of their location within programs or documents. The term is taken from the trail of breadcrumbs left by Hansel and Gretel in the popular fairytale.

Let's get started
One more time, Wordpress conditional tags will be very usefull. With them, we'll be able to know easily if the page displayed by a visitor is an article, a page, or a category archive.
Then, we'll have to use the right functions to show the site's hierarchy. Nothing difficult here, Wordpress got all the functions we need to get links to homepage, articles and single pages.
I wrote a quite clean breadcrumb function, you just need to copy/paste it in the functions.php file from your Wordpress theme. If this file doesn't exists, just create one and paste the function on it.
function the_breadcrumb() {
if (!is_home()) {
echo '<a href="';
echo get_option('home');
echo '">';
bloginfo('name');
echo "</a> » ";
if (is_category() || is_single()) {
the_category('title_li=');
if (is_single()) {
echo " » ";
the_title();
}
} elseif (is_page()) {
echo the_title();
}
}
}
Now that we have the function, nothing simpler: We just have to edit the file where we want our breadcrumb to appear – I think that archive.php, single.php and page.phpis a good choice – and call the function.
<?php the_breadcrumb(); ?>
That's all. You just created an easy way for your readers to navigate throught your blog sections.
Note, this script can be easily enhanced: For exemple, we should limit categories display and just show the first category.
And if you prefer installing a plugin instead of manually editing your theme files, you should have a look at the Breadcrumb NavXT plugin.

















Very useful tip, thanks for sharing!
Thanks it works.
Plug in was way over kill this is great!
Thanks for this one.
Just a suggestion: use single_cat_title(); instead of the_category(’title_li=’); because if you have posts listed which belongs to more than one category, the output is a little bit strange…
@Toxane: Simply great! A few users reported me the problem and I didn’t found the solution. Thanks!
This would be great if it could be implemented into the next version of openbook! Maybe enabled/disabled with a control panel checkbox!
Why not! That’s a good idea, I’ll think about it!
This is a good way to handle breadcrumbs, particularly for theme coders (not a good idea to have the theme depend on the NavXT plugin). If you intend to have breadcrumb navigation more broadly however, you shouldn’t forget about a few other possible pages, for instance:
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo”Archive for “; the_time(’F jS, Y’);}
elseif (is_month()) {echo”Archive for “; the_time(’F, Y’);}
elseif (is_year()) {echo”Archive for “; the_time(’Y');}
elseif (is_author()) {echo”Author Archive”;}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo “Blog Archives”;}
elseif (is_search()) {echo”Search Results”;}
Thanks for sharing this, Ozan! I should now rebuilt a better function =)
Thanks! I like to iplement “no plugin” solutions on my blog!
This really helped me. Thanks.
It’s doesn’t work for my theme. The page would come up blank after I put in the function on my single.php page
@TheWebpreneur.ca : Really weird…Do you have an exemple code online somewhere that I can see?
I copied and pasted my single.php code here..
http://www.thewebpreneur.ca/single-code/
JBJ - thank you for this. I am about to try it out. However, could you please tell me where I would put Ozan’s code in relation to yours?
Thank you!
@Samsara:
/* my code */
if {
…
}
/* put Ozan’s code here */
Thanks so much JBJ! You know I just did not want to screw up the blog before I even had breadcrumbs implemented correctly right? Haha!!
Just to make sure…
Like this?
/*Ozan’s code?*/
if (is_category() || is_single()) {
Cause to me it looks like it’d be…
elseif (is_page()) {
echo the_title();
/*Ozan’s code?*/
But it is the 1st way?
Thanks for spending time with me.
Ah at last, found it. Was looking all over the internet for this code, only found plugins. Thanks