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),

  5. Mike says

    Can’t seem to get this working. I’m setup with a blog roll page and trying for a breadcrumb of: sitename / blog / post name. (ie. no category used). This works in the permalink but not breadcrumb – any ideas? Thanks Bill.

  6. Cara C. says

    I have a custom post type (Homes) that is searchable by several taxonomies and their terms (Style: Ranch, Cape Cod, etc), how can I get the searched terms to appear in the breadcrumbs (i.e. Browse Homes > Search for “Ranch, 3 Bedrooms, 2 Bathrooms”)?

    • Bill Erickson says

      You’ll need to use the filter genesis_search_crumb to customize the search results breadcrumb with whatever content you’d like.

  7. Cristhian Martinez Ochoa says

    Do this have any SEO impact?
    I thought the breadcrumbs (URL) trail is not well structured after adding the blog element.

    domain.com >> domain.com/blog >> domain.com/category/post

    I did this, just because of the multisite forces blog slug and I had to do a hack to remove blog slug, but breadcrumbs still remains with blog page.

    Home >> Blog >> Category >> Post
    (Breadcrumb and URL trails are not the same)

    Now I’m not sure if this could have a negative impact in the way Google read my site structure and show breadcrumbs in search results snippets.

    • Bill Erickson says

      I’m not an SEO expert so can’t comment on the SEO impact of breadcrumbs. If you’re worried about it I recommend you use the breadcrumbs built into Yoast SEO (they will replace the Genesis ones).

  8. Rajesh says

    I want to enable breadcrumb in genesis theme but don’t want to show that up in search results, is there any way to do this??

  9. lou says

    Bill thanks for all of your nice tutorials and code snippets. I was trying to get this working with custom post types so that my breadcrumbs look like this CPT>Taxonomy>Post title. Any pointers would be greatly appreciated.

    • Bill Erickson says

      It should work in the same manner. All singular pages (single posts, single page, single cpt…) use the genesis_single_crumb filter. So either use the function above on single-events.php (or whatever your post type is), or put it in functions.php and check the post type. Then add the taxonomies as you like.

      For instance, if you are using BE Events Calendar to add an ‘events’ post type and have enabled the event-category taxonomy, use this in functions.php or single-events.php to include the category in the breadcrumb: https://www.billerickson.net/code/add-taxonomy-to-genesis-breadcrumb/

      • Nathan says

        Bill, is there a filter for archive pages? I used the method you linked to in your response to Lou and got this up and running on my CPT’s single pages, but if I visit a term archive page, it pretty much just says, “HOME / Term” without reflecting the CPT Parent-link like it does on the single-post pages where it outputs “HOME / CPT / Term / Post”

        I was trying to modify your code, but then I realized per your explanation for Lou that this is aimed at singular pages.

        • Bill Erickson says

          The genesis_archive_crumb filter should work for all archives (including CPT archives). You can use genesis_post_type_crumb filter to only target CPT archives.

          See /genesis/lib/classes/breadcrumb.php and search for “apply_filters” to find all available filters.

          • Nathan says

            Thanks, Bill. Using your suggestion, I just set up another function right below the one for the single pages, but this time I just changed the top conditional to:
            if( !is_tax(‘taxonomy-name’))
            and then I changed up the breadcrumb trail a little bit to add in the CPT archive and output the term name… and then hook the function to the genesis_archive_crumb filter and it seems to do the trick.

  10. Saurav says

    Hi Bill,
    Can you tell me how i can add tags in breadcrumb?
    Like this
    Home > Blog > Category-name> Tag-name > Sample Post

  11. Susan says

    Thanks so much! Your code worked great! I have a specific page that I wanted to add before a specific category list which looks like this:
    Home > specific page > category list > post

    so I tweaked the code for the following: https://gist.github.com/billerickson/5d94ebd52872f6c9a0226e9d98b064c1

    Now the Breadcrumb looks like:

    Home > Overview Page > Category > post

    Hope I explained it clearly. But it works like a champ for me.

    Thanks so much for the inspiration!!

    • Bill Erickson says

      Looks good to me. The only thing I’d do differently is use home_url( 'xxx-overview-page/' ) instead of hardcoding a relative URL. If the site is ever moved to a subdirectory (ex: a staging site or a local development environment) the relative URL won’t work but home_url() will.

      Another option would be to use the post ID of the page in question, like get_permalink( 1234 ) in case the URL slug ever changes in the future.

  12. Jordan Smith says

    Hey Bill, this is perfect! Thanks!

    Quick question on modifying custom post type breadcrumbs.

    I have has_archive set to false for a custom post type so that I can tie in a page using an ACF flexible content field template I use.

    But in the breadcrumbs it still attempts to connect to the default team archive template in WordPress.

    I was able to add the new page to the breadcrumbs using the approach above but now it has that page (Team) AND the static Team text that is associated with the archive for Team.

    Home > Team > Team > Jordan Smith

    How can I filter out the second “Team” from $crumb?

Leave A Reply