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 the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

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

Let's Talk

Reader Interactions

Comments are closed. Continue the conversation with me on Twitter: @billerickson

Comments

  1. 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.

  2. 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.

  3. 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).

  4. 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??

  5. 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.

  6. 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

  7. 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.

  8. 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?

  9. Alex says

    Hey Bill, thank you for your awesome site.

    Is there a way to show a page instead of a category? Because I wan’t my category to be a page.

    Thank you and I really appreciate your help!