Breadcrumbs are becoming more and more popular in new WordPress templates. People want added functionality to their blog and breadcrumbs are a nice little addition that if done right, really add a uniqueness to your theme design. Today I will show you how to very simply add breadcrumbs to any theme design in WordPress.

Step 1 - Open Up Functions.php

If you're theme doesn't have a functions.php file, create one, and add this:

<?php
 
?>

Be sure there is absolutely no whitespace above or below the php brackets.

Once you're in your functions.php file, copy and paste the following code in there:

/*Breadcrumbs*/
function the_breadcrumb() {
	echo 'You are here: ';
	if (!is_home()) {
		echo '<a href="';
		echo get_option('home');
		echo '">';
		echo 'Home';
		echo "</a> &raquo; ";
		if (is_category() || is_single()) {
			if (is_single()) {
				echo the_title();
			}
		} elseif (is_page()) {
			echo the_title();
		}
		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";
		}
		elseif (is_404()) {
			echo "404 Error";
		}
	}else{
		echo '<a href="';
		echo get_option('home');
		echo '">';
		echo 'Home';
		echo "</a>";
	}
}
/*End of Breadcrumbs*/

Once you have it pasted, close functions.php, you're done with it.

Step 2 - Add the Breadcrumbs to Your Theme

What you just did was create a function for your theme. It actually does nothing until it is called to from another theme file, so that's what we're going to do now.

Go to the file where you would like your breadcrumbs to appear. For example, in my theme here on ForTheLose.org, I have my breadcrumbs in header.php, right below the header on the left. Once you're there, paste this snippet wherever you want the breadcrumbs to appear:

<?php the_breadcrumb(); ?>

And that's it. You're done. WordPress will do the rest of the work for you. If necessary, open up your style.css and style the look of the breadcrumbs.

If you liked this post, stay updated. Follow me on Twitter or subscribe to our RSS Feed via email.

Post Tags: , , ,

Related Posts

Like this post? Spread it!