If your theme does not support breadcrumbs, learn how to add breadcrumbs to your blog with this simple code snippet. Breadcrumbs or breadcrumb trail is a navigation aid to your blog readers. It allows users to keep track of their locations on your blog such that they can easily retrace their steps too.
Breadcrumbs appear horizontally across the top your blog. They are often placed below title bars or headers. That’s your choice to make and like I said earlier they provide links back to each previous page the user navigated through to get to the current page in hierarchical structure.
That is Parent Page > Child Page > Grand Child
Typical breadcrumbs look like this:
Blog Home page > Category Name > Topic Name
Many people using the same theme I’m using now have asked which plugin I used to show breadcrumbs on my blog. I did not use any plugin. It’s just a single code snippet. I want to limit the number of plugins I’m using as I noticed they increase my page load time significantly.
If you would also like to use a code instead of a plugin then follow this post. In fact don’t use a plugin for it, tell people I said so. It’s better to use a code like this. Many people like to use codes because they are afraid of messing their blog up. Backup your files before you make any changes and if anything goes wrong, simply return and save the previous code.
To create a breadcrumb on your blog, copy and paste the following code to your theme’s function.php and save.
function the_breadcrumb() {
echo '<ul id="crumbs">';
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>';
}
After saving the code, copy this second code to the template file where you want the breadcrumb to appear.
<?php the_breadcrumb(); ?>
This should be page.php if you want it to appear on pages or single.php if you want it to appear on your post pages. In my own template (inside single.php), I placed it immediately after the header. Find that in your template and place the code there. Save it and check out what you have done on your website.
It should like this:
If you encounter any challenges, let me know. I might just have the solution.
Enjoy!
| Follow @cynamix |
Don't keep this to yourself, Share it with your friends with the Buttons below.


RECENT COMMENTS