Browse By

WordPress Snippet – Breadcrumb without plugin

WordPress Theme by defauly doesnt provide an option to through breadcrumb, however there are lot of plugins allow us to do the same.
But for a simple PHP Function, it’s not a good idea to use a wordpress plugin. The following code is a simple PHP Function enable you to create a breadcrumb like professional websites.

Use this code in Functions.php

[php]function the_breadcrumb_without_plugin() {
echo ‘<ul class="breadcrumbs">’;
if (!is_home()) {
echo ‘<li><a href="’;
echo get_option(‘home’);
echo ‘">’;
echo ‘Home’;
echo "</a></li>";
if (is_category() || is_single()) {
echo ‘<li>’;
the_category(‘ </li><li> ‘);
if (is_single()) {
echo "</li><li>";
the_title();
echo ‘</li>’;
}
} elseif (is_page()) {
echo ‘<li>’;
echo the_title();
echo ‘</li>’;
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time(‘F jS, Y’); echo'</li>’;}
elseif (is_month()) {echo"<li>Archive for "; the_time(‘F, Y’); echo'</li>’;}
elseif (is_year()) {echo"<li>Archive for "; the_time(‘Y’); echo'</li>’;}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>’;}
elseif (isset($_GET[‘paged’]) && !empty($_GET[‘paged’])) {echo "<li>Blog Archives"; echo'</li>’;}
elseif (is_search()) {echo"<li>Search Results "; echo'</li>’;}
echo ‘</ul>’;
}[/php]

Use this code in Required Theme Section like header.php

[php]
<?php the_breadcrumb_without_plugin(); ?>
[/php]