WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

if ( ! function_exists( 'seobreadcrumbs' ) ) : 
function seobreadcrumbs() {
$separator = '›';
$home = 'Home';
echo '<div xmlns:v="http://rdf.data-vocabulary.org/#" class="seobreadcrumbs">';
global $post;
echo '  <span typeof="v:Breadcrumb">
You are Here :- <a rel="v:url" property="v:title" href="http://www.how2blog.in">Home</a>
</span> ';
$category = get_the_category();
if ($category) {
foreach($category as $category) {
echo $separator . "<span typeof=\"v:Breadcrumb\">
<a rel=\"v:url\" property=\"v:title\" href=\"".get_category_link($category->term_id)."\" >$category->name</a>
echo '</div>';}

function show_crumbs() {
if(is_single() || is_tag() || is_search() || is_404() || is_page() || is_category()) { ?>
<?php seobreadcrumbs(); ?>
<?php }}

/* End*/

I use these codes to show breadcrumb trail. The problem I’m having with it is, some times its getting messed up let me clarify suppose I’ve category named

Social Media parent category is Facebook

When I publish a post under facebook It should show like

# Social Media >> Facebook

But some times facebook is coming 1st then Social Media 2nd like this:

# Facebook >> Social Media

And Google also displaying this way.

Can anybody help me regarding this?

share|improve this question
Does it sometimes show up with the child category before the parent category, or does it always show up that way? – Chip Bennett Sep 1 '12 at 14:31
up vote 2 down vote accepted

My initial thought is that the issue is here:

$category = get_the_category();

If get_the_category() is returning categories in reverse-hierarchical order, then you can do this to put them back in order:

$category = get_the_category();
$category = array_reverse( $category );

However, I'm confused by this:

But some times facebook is coming 1st then Social Media 2nd...

If it is only happening sometimes, and not always, then I suspect that there is an issue somewhere else.

share|improve this answer
Oh my gosh it works :) I've no words left to tnx you... just want to say my hat goes off to you mate... God bless you... – Arafin Shaon Sep 1 '12 at 15:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.