Display Breadcrumbs On WordPress Post Without Plugin

Breadcrumbs are used to show the process to which you would navigate to a page. For posts on your wordpress blog you can use breadcrumbs on your posts to show the categories which this post is in.

Displaying what categories the post is in means you can add another link to the category so that if the visitor is interested in this category they can easily navigate to more posts on the subject.

The function below the_breadcrumb() will get the breadcrumbs for the current page this will need to go into the functions.php page.

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 this function is in the functions.php page you can call this from any page within the post loop.

Go to your single.php page and add the following code anywhere you want to display the breadcrumbs.

<?php the_breadcrumb(); ?>

Advertise here

Comment