Azharkamar.com

Displaying Breadcrumbs in WordPress

Tutorials
4 Apr 2011
2 comments

Breadcrumbs are important for web developers who want to provide an aid for their users in navigating through their site, especially in cases where the website contains deep links.

I don’t usually implement breadcrumbs but the client for this particular website that I’m currently developing specifically required it.

So here are the code snippets you can use to easily display breadcrumbs in WordPress.

1. Create a Function in functions.php

First of all, add this piece of code at the bottom of your theme’s functions.php file (before the ?> tag).

function the_breadcrumb() {
	if (!is_front_page()) {
		echo '<a href="';
		echo get_option('home');
		echo '">Home';
		echo "</a> > ";
		if (is_category() || is_single()) {
			the_category(' ');
			if (is_single()) {
				echo " > ";
				the_title();
			}
		} elseif (is_page()) {
			echo the_title();
		}
	}
	else {
		echo 'Home';
	}
}

2. Call the Function

Then, call the function that will display the breadcrumbs by adding these codes into your single.php and page.php files. Just add this line anywhere in any of your template files where you want the breadcrumbs to appear.

<?php the_breadcrumb(); ?>

Good luck!

Author - Azhar Kamar
2 Comments Revolving around this Article
  1. diana

    hi, i want to ask about previous and next link..
    let say, i want to display prev and next link in the main entry…so i set display post to 1..
    but the entries in Categories also changed to 1 only..
    is it posible to display all the entries in certain category even if i set the display post to 1?

  2. wp

    Wp Plugin…

Write a Comment! NOW! :)

Current ye@r *