Breadcrumbs are the important part of our website, in wordpress there are several plugins are available for this, but below i posted the code for custom breadcrumbs for our wordpress site. Just add this below code in to your current wordpress theme functions.php and call the second step.
Step 1
[php]
‘; // tag before the current crumb
$after = ‘‘; // tag after the current crumb
global $post;
$homeLink = get_bloginfo(‘url’);
if (is_home() || is_front_page()) {
if ($showOnHome == 1) echo ‘
‘;
} else {
echo ‘
if ( is_category() ) {
$thisCat = get_category(get_query_var(‘cat’), false);
if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ‘ ‘ . $delimiter . ‘ ‘);
echo $before . ‘Archive by category “‘ . single_cat_title(”, false) . ‘”‘ . $after;
} elseif ( is_search() ) {
echo $before . ‘Search results for “‘ . get_search_query() . ‘”‘ . $after;
} elseif ( is_day() ) {
echo ‘‘ . get_the_time(‘Y’) . ‘ ‘ . $delimiter . ‘ ‘;
echo ‘‘ . get_the_time(‘F’) . ‘ ‘ . $delimiter . ‘ ‘;
echo $before . get_the_time(‘d’) . $after;
} elseif ( is_month() ) {
echo ‘‘ . get_the_time(‘Y’) . ‘ ‘ . $delimiter . ‘ ‘;
echo $before . get_the_time(‘F’) . $after;
} elseif ( is_year() ) {
echo $before . get_the_time(‘Y’) . $after;
} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() != ‘post’ ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo ‘‘ . $post_type->labels->singular_name . ‘‘;
if ($showCurrent == 1) echo ‘ ‘ . $delimiter . ‘ ‘ . $before . get_the_title() . $after;
} else {
$cat = get_the_category(); $cat = $cat[0];
$cats = get_category_parents($cat, TRUE, ‘ ‘ . $delimiter . ‘ ‘);
if ($showCurrent == 0) $cats = preg_replace(“#^(.+)\s$delimiter\s$#”, “$1”, $cats);
echo $cats;
if ($showCurrent == 1) echo $before . get_the_title() . $after;
}
} elseif ( !is_single() && !is_page() && get_post_type() != ‘post’ && !is_404() ) {
$post_type = get_post_type_object(get_post_type());
echo $before . $post_type->labels->singular_name . $after;
} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ‘ ‘ . $delimiter . ‘ ‘);
echo ‘‘ . $parent->post_title . ‘‘;
if ($showCurrent == 1) echo ‘ ‘ . $delimiter . ‘ ‘ . $before . get_the_title() . $after;
} elseif ( is_page() && !$post->post_parent ) {
if ($showCurrent == 1) echo $before . get_the_title() . $after;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = ‘display_name . $after;
} elseif ( is_404() ) {
echo $before . ‘Error 404’ . $after;
}
if ( get_query_var(‘paged’) ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘ (‘;
echo __(‘Page’) . ‘ ‘ . get_query_var(‘paged’);
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘)’;
}
echo ‘
‘;
}
} // end qt_custom_breadcrumbs()
?>
[/php]
Step 2
After adding the code into functions.php add the below code to where you want to use this function.
[php]
[/php]
Well done friend…
Big thanks to you!
thanks. I am using it. Is there a way to reverse it and stack the crumbs starting on the left and build out to the right? last-page << third-page << second-page << Home-page
Incase I wanted to push this into a left hand corner as my right contains date and time stamps?
Thanx, this helped me alot!
This is a good solution, but you could have added more elaborations on the code. Secondly, you might consider adding microdata for the breadcrumbs, so the breadcrumbs will also appear in google search results.
Do you have an example for this please ?
Very Helpful. Thanks
Very cool, it works with WP 3.6. I was wondering how to make it responsive. With max-width:767px do not display breadcrumbs. Via CSS it does not work.
Works with custom posts.. yay!
Coool…Works Fine, but I want something more, I have custom post type and taxonomies, and how to work with this, In CPT single page I am getting home>Post Type>single post name, I want to show up the taxonomy term also… Like I have this, a Post type Publications, and taxonomy publication_type, and in publication_type terms like article, Poems etc, So I select a post from article, in single page i want to get Home>Publications>Poems>post title…. Is it possible???? Tanx in advance .
Any How your work is cool, and so helpful. 🙂
Thank u
ok . done task thank for share 😀
I got errors on WP 3.8.1 (“headers blah-blah” when I try to edit a post with activated breadrumbs from the template)
thanks, it served me very helpful
not working on a blog page..
wow very nice code thnx for help
thanks alot it’s very helpful.
Thank you very much. such a wonderful tricks. Its really works for me.
w el nby enta prince
good job… worked perfectly for me
Great job! But i have a question, my blog page is set on home.php, and with this breadcrumb it doesn’t show the blog title nor the blog title before a category. it’s like: Home >> Category >> Post, i want to show like: Home >> Blog >> Category >> Post… how can i do that? Thank you!
Great dear
It’s very special, a few ways I use to find breadcrum on my site, just above methods can work. Thank the guest, I am very happy with the tutorial that you gave.
Big thanks indeed, I am currently using it and let you know how it performs on my site.
http://mohanmekap.com
Wonderful blog & good post. It is really helpful for me, awaiting for more new post. Keep Blogging ! White Hat World >>>>
Superb… Your code helped us to add breakcumbs to our wordpress blog. Yeah…it just saved us from adding another plugin !!!
Thank you
Great post! How to make this breadcrumbs function to noindex?, hide it from SERPs. Please help me out.
asaadadad
asdsadaaadaaad
Thanks for the effort. How can I include the sections of the breadcrumb trail this misses?
This code creates:
Home » Category » Deeper Category » Current Post Title
But I need:
“The actual title of my site” » Category » Deeper Category » Deeper Category » Deeper Category » Deeper Category » “I don’t need current page title”
Delimiter doesn’t display correctly on Pages with multiple levels. To fix change line 81 from:
if ($i != count($breadcrumbs)-1) echo ‘ ‘ . $delimiter . ‘ ‘;
to:
if ($i != count($breadcrumbs)-1) $returnString .= ‘ ‘ . $delimiter . ‘ ‘;
Thank you very much! Really works and is useful.
I got this error : Strict Standards: Only variables should be passed by reference in C:xampphtdocswp-theme-devwp-contentthemesviperincviper-functions.php on line 231, what should i do?
Thanks 🙂
I could do a PHP implementation to activate breadcrumbs using the following Guide To Install Breadcrumbs: http://www.codingalpha.com/easy-guide-to-add-breadcrumbs-in-wordpress-for-navigation/
A very simple and easy to set this code:
This guide helped me to install breadcrumbs in the best possible way and without damaging the PHP code.