How To: Add Breadcrumbs without a Plugin

by Greg Rickaby on December 30, 2009

Post image for How To: Add Breadcrumbs without a Plugin

I’m sure this tutorial has been done a hundred-times over, but I blog so I don’t have to remember. This function will help you eliminate a bloated, self-serving plug-in like Yoast Breadcrap; by using the ever popular (and super useful) conditional tags

Step 1: Open custom_functions.php and paste the following code at the bottom:


// Build Breadcrumbs
function the_crumbs() {
	if (!is_home()) {
		echo '<a href="';
		echo get_option('home');
		echo '">';
		echo 'Home'; // Home Link Text, change this to meet your needs
		echo "</a> >> ";
		if (is_category() || is_single()) {
			the_category(', ','&title_li=');
			if (is_single()) {
				echo " >> ";
				the_title();
			}
		} elseif (is_page()) {
			echo the_title();
}}}

// Show Breadcrumbs
function show_crumbs() { ?>
<div id="crumbs">
	<?php the_crumbs(); ?>
</div>
<?php }
add_action('thesis_hook_before_content','show_crumbs');

Step 2: Open custom.css and paste the following:


/* Breadcrumbs */
#crumbs {
	font-size: 11px; /*font size, change this to whatever you want*/
	padding: 10px 0px 0px 10px; /*10 padding top, 10 padding left*/
}
#crumbs a {
	color: #00F /*change this to whatever color you want*/
}
#crumbs a:hover {
	text-decoration: underline; /*underline the links on a mouse over*/
}

UPDATE 6.29.10 Thank you Chris for the tip on multiple categories. I have updated the code above with your fix!

Related posts:

  1. How To: Create a Custom Page Template
  2. How To: Create a Featured Content Slider
  3. How To: Add More Sidebars
  4. How To: Create a Sub-Loop in Thesis
  5. How To: Upgrade to Thesis 1.6 (in 15 minutes)

{ 13 comments… read them below or add one }

lightweight tent July 29, 2010 at 14:32

Thanks for sharing. I already use your code in my website . it help me solve the multi category problem. Thanks you.

Reply

DEVESH @ TECHNSHARE July 8, 2010 at 10:37

Hey Greg,

Very neat code. Thanks for sharing.

Reply

Genius June 29, 2010 at 05:20

Thanks for the tip. How can I make the breadcrumbs inherit the fonts and body colors that I chose in Design Options?

Reply

Daniel May 29, 2010 at 11:25

Nice one Greg for the snippet, I’m currently creating a ‘cheat-sheet’ of my commonly used hooks to save time and this will be added to the mix. Also props to Chris for the multiple category fix, I’ve run into that problem before!

Reply

Greg Rickaby June 24, 2010 at 09:52

Rockin’ awesome. Glad it’s helping people!

Reply

Jeff May 27, 2010 at 17:36

@james – I added the following lines to get pages and subpages. I think it only works for 1 subpage level (as that’s all I need)… but should be easy to set for another.

take out
elseif (is_page()) {
echo the_title();
}}}

and add in the following….

if ( is_page() && $post->post_parent ) {
echo ‘post_parent) . ‘ “> ‘;
echo get_the_title($post->post_parent) . ”
“;
echo ” >> “;
} if ( is_page() ) {
echo the_title();
}
}
}

Reply

Jeff May 27, 2010 at 16:20

I tried to get 2 plugins to work with thesis and hooks but couldn’t get it. This took less than 30 seconds and works great. A few customization things with the CSS and I’m set. Thanks a ton!

Reply

Hesham @ FamousBloggers April 23, 2010 at 19:19

Very nice, I have check the code.. works great!

Reply

George Serradinho April 23, 2010 at 03:53

Thanks for this tutorial, it has really helped me out.

I liked the plugin that could do this, but I always do my best to get things displaying without using plugins and this just worked perfectly.

Reply

Avinash D March 6, 2010 at 15:05

@Greg- Nice snippet there mate…

@Chris- Thanks for adding on to it…

Reply

James February 12, 2010 at 22:42

It works, but how to show posts & page parents?

Reply

Chris Harrison February 1, 2010 at 00:20

Thanks for posting this. I had an issue with it when a post was assigned to multiple categories, but it’s an easy fix: the_category('title_li='); should be changed to the_category(', ','&title_li=');. Without this adjustment, your code will display title_li in front of each additional category the post is assigned to.

Reply

Hesham June 22, 2010 at 22:59

I didn’t notice that at the beginning, but then I had the same problem so.. thank you so much for posting this Chris!

Reply

Leave a Comment

{ 6 trackbacks }

Previous post:

Next post: