Breadcrumbs are very useful navigation tools, especially for sites with multiple levels and more than a dozen pages. While there are a few breadcrumb navigation plugins for WordPress, sometimes it’s a bit of an overkill when the job can be done with just a few lines of code.
The function below will insert a breadcrumb navigation for the pages in your WP site, and highlight the news/blog page when within that section, etc.
Usage:
- Copy the code below into your theme’s functions.php file. If your theme doesn’t have one, create it.
- Insert <?php rm_bread_crumbs(); ?> in your theme where ever you’d like the bread crumbs displayed.
//breadcrumb function
function rm_bread_crumbs() {
global $post;
$crumbs = '<p><a href="'.get_option('home').'">Home</a>';
//if the page has a parent add title and link of parent
if($post->post_parent) {
$crumbs .= ' » <a href="'.get_permalink($post->post_parent).'">'.get_the_title($post->post_parent).'</a>';
}
// if it's not the front page of the site, but isn't the blog either
if((!is_front_page()) && (is_page())) {
$crumbs .= ' » '.get_the_title($post->ID);
}
//if it's the news/blog home page or any type of archive
if((is_home() ||(is_archive()))) {
$crumbs .= ' » '.get_the_title(get_option(page_for_posts));
}
//if it's a single news/blog post
if(is_single()) {
$crumbs .= ' » <a href="'.get_permalink(get_option(page_for_posts)).'">'.get_the_title(get_option(page_for_posts)).'</a>';
$crumbs .= ' » '.get_the_title($post->ID);
}
$crumbs .= '</p>'."\n";
echo $crumbs;
}

