Adding “Blog” to Genesis Breadcrumbs

One of the many great features of Genesis is the built-in breadcrumbs. No plugin is required, and they’re VERY customizable. Of course there’s the Breadcrumb toggles in Genesis > Theme Settings that let you specify where they show up. But you can do a lot more with code.

If you look in /genesis/lib/classes/breadcrumb.php you’ll see all the code used for the breadcrumbs. For each instance of a breadcrumb (single, archive, home, blog, page…) there’s a function for it and a filter to modify that function’s output.

To modify the breadcrumbs, just pick the filters you want to use and write a function that does something with the $crumb.

In this example, I’ll  add “Blog” before “Category” on the category and single breadcrumbs. By default, the breadcrumb renders this:

  • On blog home: Home > Blog
  • On category: Home > Category
  • On single post: Home > Category > Post Title

Here’s how I do it:

The bottom two lines are the filters I want to modify (single and archive). In my function I’m using get_option('page_for_posts') to get the ID of the blog homepage.  I’m then using the core WordPress functions get_permalink() and get_the_title() to return the permalink and title of this page ID.

This line ( if ( is_singular( 'post' ) || is_category() ) ) ensures this only applies to blog posts and post categories. The filters are also used for posts in custom post types and taxonomies.

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk

Reader Interactions

Comments

    • Bill Erickson says

      Can you post the exact code you’re using? It looks like you’re using get_permalink() and get_the_title() without adding get_option( 'page_for_posts' ) inside it.

        • Bill Erickson says

          It sounds like the issue is that you’re using the homepage for your blog. This code only works (and is only needed) if you’re using a custom page for your blog, set in Settings > Reading. When your blog is your homepage, the Home link goes to your blog already.

  1. Bhaskar Sarma says

    Bill, does this method still work after the latest update to Genesis and Prose? I followed the code but it seems to be no -go.

    • Bill Erickson says

      Yes it does since the latest version didn’t change the Breadcrumbs. Genesis is built to be very backwards compatible, so updating it should never break existing functionality like this.

  2. Paul says

    Thanks Bill, this worked great. Just one thing though, how would I get the breadcrumb to not show the category name on posts? (As the url and breadcrumb don’t match)

    Currently shows:
    Home / Blog / {category} / {name of post}

    Want to show:
    Home / Blog / {name of post}

    Any help would be much appreciated!

  3. Omscowonder says

    You are simply the best.
    i just added the breadcrumbs to my genesis child themes, it works like a charm

    • Bill Erickson says

      Remove the add_filter( ‘genesis_single_crumb’ )… line, since that code applies it to the single posts.

      It’s also a good idea to remove the is_singular() conditional. Even though this code doesn’t run on single posts once you make the above change, for clarity all references to the single post should be removed.

  4. Kevin says

    Any clue how to get blog in the URL? When I click blog it has site.com/blog but when it goes to a single page it’s just site.com/blog_title

    I had this working a ways back but lost the snippet : / and am thumping my head on the desk now! Thanks!

    • Bill Erickson says

      Go to Settings > Permalinks, select “Custom” and then type /blog/ . That will add /blog/ to the front of all the single post permalinks.

      • Kevin says

        Yup figured that part out but all my custom post types and taxonomies had /blog/ placed in front of their URLs as well, after some research I added the below code when registering CPT’s and TAXs and it starts at the root URL removing blog, thanks for the reply as always and if you have a better approach I am all ears. Hope that’s not too much code to include:

        Front set to false being the key bit here.
        ‘rewrite’ => array( ‘slug’ => ‘promotions/’, ‘with_front’ => false),

Leave A Reply