SEO Friendly Breadcrumb for WordPress

Last day I wrote about the SEO Friendly Breadcrumb Format, I have implemented those formats in my WordPress site. And here is the code which is written for WordPress.

Add this PHP code at the end of functions.php file from the theme folder

<?php

if ( ! function_exists( 'breadcrumbs' ) ) :
function breadcrumbs() {

	$delimiter = '&rsaquo;';
	$home = 'Home';

	echo '<div xmlns:v="http://rdf.data-vocabulary.org/#" class="breadcrumb">';

	global $post;
	echo '	<span typeof="v:Breadcrumb">
 			<a rel="v:url" property="v:title" href="'.get_bloginfo('url').'">'.$home.'</a>
			</span> '; 

	$cats = get_the_category();
	if ($cats) {
	  foreach($cats as $cat) {
	  	echo $delimiter . "<span typeof=\"v:Breadcrumb\">
	    			<a rel=\"v:url\" property=\"v:title\" href=\"".get_category_link($cat->term_id)."\" >$cat->name</a>
	    		</span>";
	  }
	}

	$posttags = get_the_tags();
	if ($posttags) {
	  foreach($posttags as $tag) {
	  	echo $delimiter . "<span typeof=\"v:Breadcrumb\">
	    			<a rel=\"v:url\" property=\"v:title\" href=\"".get_tag_link($tag->term_id)."\" >$tag->name</a>
	    		</span>";
	  }
	}

	echo '</div>';

}
endif;

?>

The above code will generate the breadcrumb from the post categories and post tags values of the current post. The parent category will be show at the first then its child, and finally add if any tag presents.

Add the following function call in your single.php file.

<?php breadcrumbs(); ?>

Place this code above the the_title() function or below the_content() function calls.

Add the following CSS in you Style.css

/* BreadCrumbs CSS*/
.breadcrumb {
	font-size: 11px;
}
.breadcrumb a {
	color: gray;
	text-decoration: none;
}
.breadcrumb a:hover {
	color: #178A00;
}

So now your WordPress blog’s breadcrumb is Search Engine Optimized. You can see the results from your next post onward. Its so simple :)

Also See : SEO Friendly Breadcrumb Format


Share Your Thoughts

17 Responses to SEO Friendly Breadcrumb for WordPress

  1. Pingback: Membuat SEO Friendly Blog : Google Rich Snippets Breadcrumb Wordpress | Majuterus

  2. Need help : I was try it on my blog but why show error below :
    Warning: Cannot modify header information – headers already sent by (output started at /home/fajarram/public_html/wp-content/themes/Maya/compositio/functions.php:168) in /home/fajarram/public_html/wp-includes/pluggable.php on line 866

  3. Pingback: SEO Rich Snippets Breadcrumb Tanpa Plugin | Alang Fauzi Bertuah

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="">