WordPress SEO: Breadcrumb for each Post!

All of you may have already noticed that Google has started displaying breadcrumb in place of URL at the bottom of each search result. So, if you have breadcrumb for posts then that will visible to person searching for something and your page come in result page.

Breadcrumb is displayed in SERP, when you have breadcrumb. If you do not have then your page URL is shown. Is breadcrumb is good for SEO? I do not have complete answer for you. You can say it is good for SEO and it provides navigation information to the user. Also, Google may have found this useful so It has started showing Breadcrumb in Search Result. But, my point is blog generally do not go deeper in the path. So, in this case what is the use of Breadcrumb in blog.

This post is about, why and when breadcrumbs is important and how to implement breadcrumbs yourself in wordpress.

Many blog template do not have breadcrumb. But my template has it. Your template may have it! So, decide you want to use breadcrumb or not? This is coming into search result and this may affect your Click through rate on SERP and so your SEO work.
If you have decided that you need breadcrumb and your wordpress template do not have this then you can add few lines of code. In case, you already have breadcrumb then you need to check - is this something impressive! Use site:yoursite.com in Google search input box to see your result.

BreadCrumb Code and explanation about how to implement it:

Search for Post Title in single.php WordPress template file. Post Title comes from the_title();, so search for the_title(). Just before it you need to add the breadCrumb information.

Here is HTML what I have added on single.php template (new BreadCrumb):


<div id="postpath">
	<a href="<?php echo get_settings('home'); ?>/"><?php _e('Home'); ?></a>
		&gt; <?php echo tagAndCatBreadCrumb(); ?>
		&gt; <?php the_title(); ?>
</div>

My template already has bread crumb navigation but it had only categories between Home and PostTitle. It had categories only in breadcrumbs navigation and as I have already said my Categories are not very good representation of the post. So, I have thought to add tags as well. (I thought to restrict my categories so that it can fit into blog menu bar).

Here is what I remember it was before.
Old code on my WordPress template:


<div id="postpath">
	<a href="<?php echo get_settings('home'); ?>/"><?php _e('Home'); ?></a>
		&gt; <?php the_category(', '); ?>
		&gt; <?php the_title(); ?>
</div>

You see, I am calling tagAndCatBreadCrumb() function for breadCrumb generation. I have written this function for customizing my breadCrumb. You can directly define this function in single.php file or inside your template function.php file. In the widget editor, you will find function file also. Be careful and take backup of your file. In function.php file you may have class defined and few functions may be outside of the class. This function - tagAndCatBreadCrumb will also go outside of class. Just go to last of the page and add this function.

Here is the PHP function - tagAndCatBreadCrumb() I have written for customizing my breadCrumb:


<?php
/*
* Categories and first few tags as bread crumb
*/
if (! function_exists('tagAndCatBreadCrumb')) {
	function tagAndCatBreadCrumb() {
		$posttags = get_the_tags();
		$count=0;
		if ($posttags) {
			 foreach($posttags as $tag) {
				 $count++;
				 // no. of tags to show
				 if ($count <= 2) {
				 	$ptags[] = '<a href="'. get_tag_link($tag->term_id) . '" rel="tag">'. ucwords($tag->name) . '</a>';
				 }
			 }
			 $tagCatBreadCrumb = the_category(', ') . ' &gt; ' . implode(', ', $ptags);
			 return $tagCatBreadCrumb;
		}
	}
}
?>

First if condition is just to make sure, we are not defining the same function twice.
Chance is extremely rare. If there was a function for breadcrumb then it will be mentioned in you single.php file. You can see the name there. If you have a function there then it will be better to modify that or let it there and add this function, so that you can use that in case you made mistake. Yes, your original function name should not be same otherwise this function will not come into effect due the definition inside if condition.

In the function, I used something unusual. It is $count. This is used so that I do not display all the tags. If I have used so many tags for a post then this breadcrumb will become very long for that post. So, I have fixed it to display two tags for my breadcrumb. Your tags in post will not get affected by this. Function get_the_tags() is wordpress function which return each tags in object. Each Object for a tag holds tag name and term_id, etc. I tried to use $tag->term_id but that was not working. All tags are going in Database without any order in my WordPress template. If I could have used $tag->term_id then it would have taken just two tags in the order I have added at the time of post creation. But here it will take two tags from the alphabetical order of all tags. If you want to show more tags then you can increase the value in if condition (no. of tags to show). For all tags to display, just remove the if condition. The function get_tag_link() converts the tag into link.

So, you see code for this breadCrumb is very very small and it will not affect wordpress speed anyway, but it will give your visitor or searchers beautiful information about the post. and in turn it can affect click-through on SERP.

  • # 1 - by freakenstein

    Ah, well i'll see what Google does with it 🙂

    besides i added some extra code, so it works if an article doesn't have tags.

    else {
    $tagCatBreadCrumb = the_category(', ');
    return $tagCatBreadCrumb;
    }

Comment pages
1 2 1365
Comments are open for an year period. Please, write here on Facebook page.