Site Breadcrumbs

This element allows you to add and style breadcrumbs across your site. Includes support for schema markup, displaying nested taxonomies, custom post types & customization over the output, prefixes etc.

sitebreadcrumbs copy

Use BricksExtras markup, or your preferred plugin

The BricksExtras breadcrumbs follows Google’s recommended markup with structured data and will be sufficient for most site structures.

However, every SEO plugin has a slightly different opinion on how breadcrumbs should be structured and configured, which may be based on individual page settings that you already configured with that plugin.

So to cover all cases..

If you instead prefer to use the output/configuration from an SEO plugin you’re using, you can also just use this element to output and style the breadcrumb links directly from the plugin you’re using to manage your breadcrumbs instead.

Each breadcrumb source has its own settings, depending on what the SEO plugin allows for. For some of them, setting up the breadcrumbs behavior would be done from their settings page.

Supported sources for breadcrumbs..

General settings for all breadcrumbs

Breadcrumbs prefix: A prefix can be added to any the different breadcrumb, regardless of the source. eg ‘You are here: ‘

Link styles: Style just the links from the breadcrumb list. (See example styling in the screenshot at the top of these docs) These styles can be applied to any breadcrumbs, regardless of source.

Current item: Style the breadcrumb for the ‘current’ page only. Currently not available if using ‘All in One SEO’ as the breadcrumb source.

BricksExtras Configuration

Configuration for the BricksExtras breadcrumbs.

Include home page link – By default every breadcrumb list will start with a link to the home page as the very first item, this can be removed.

Home URL – Change the URL for the home link, default is {site_url}

Home label – Change the label for the home link, default is ‘Home’

Search Prefix – By default the text will show “Search results for ‘search term‘”, this can be changed or removed to just show the search term by itself.

Author Prefix – By default the text will show “Archives for author’s name“, this can be changed or removed to just show the author’s display name by itself.

Error 404: – By default the text will show “404 Error: Page not found”

Include posts page link – When viewing single posts, the ‘blog’ page (ie the posts page) link can also be included in the breadcrumbs.

Nest taxonomies – When enabled, all parent/grandparent taxonomies will display.

For eg, if visiting a taxonomy term, which happens to be a child of a child..

Enabled: Home > Taxonomy Term > Child Taxonomy Term > Grand Child Taxonomy Term
Disabled: Home > Grand Child Taxonomy Term

Priority Category – You can choose a category that will be shown in the breadcrumbs in situations where a post is in multiple categories.

Schema Markup – Automatically add https://schema.org/BreadcrumbList to the list, the list items and links.

Separator – The character that separates the items in the list, default is »

Include CPT archive link for taxonomies – If viewing single CPT posts and the CPT has a main archive page, this will be included in the breadcrumbs.

For situations where you need to change the behavior of the breadcrumbs conditionally, there is now a PHP filter to change the items (the crumbs) in the breadcrumb trail.

add_filter( 'bricksextras/breadcrumbs/', function( $crumbs ) {

    // $crumbs is an array of the items inside the breadcrumb trail.
    return $crumbs;
});

Being familiar with PHP conditions and WordPress functions will be required, but here are some examples just to show it in action.

Examples

For single posts that are automatically put in the uncategorized category, by default if you have chosen to display categories you’d see this – Home > Uncategorized > Post Title.  (here the $crumbs array would contain three items, one for each crumb in the trail.)

Example 1: Replace any string (say we want to change the uncategorized archive link URL. We want it to change from ‘category/uncategorized/’ to ‘my-custom-page/’)

add_filter( 'bricksextras/breadcrumbs/', function( $crumbs ) {

  if ( is_singular('post') && in_category('uncategorized') ) {
		
      /* replace 'category/uncategorized/' in the link URL 
         with 'my-custom-page/' */
      if ( isset( $crumbs[1] ) ) {

        $crumbs[1] = str_replace( 'category/uncategorized/', 'my-custom-page/', $crumbs[1] );

      }
  }

 
  return $crumbs;

});

Example 2: Remove a crumb (say we want to remove the uncategorized item from the array altogether)

add_filter( 'bricksextras/breadcrumbs/', function( $crumbs ) {

  if ( is_singular('post') && in_category('uncategorized') ) {
		
      /* remove the second item (index 1) from the array */
      if ( isset( $crumbs[1] ) ) {
        unset( $crumbs[1] );
      }
  }

 
  return $crumbs;

});

Example 3: Insert a new crumb (Say we have a CPT named ‘product’ (not WooCommerce product), and a custom taxonomy ‘product-category’.  if the product being viewed has a product-category, add that category archive page link to the breadcrumbs)

Here we need to add a new item to the array. There’s a helper function for creating a new crumb with the correct markup.

\BricksExtras\Helpers::breadcrumb_item($url, $text, $maybeLink, $maybeSchema)

Parameters;

  • $url (string): The URL of the breadcrumb item
  • $text (string): The text to display
  • $maybeLink (boolean): Whether to output as a link (optional, defaults to true)
  • $maybeSchema (boolean): Whether to include schema markup (optional, defaults to true)
add_filter( 'bricksextras/breadcrumbs/', function( $crumbs ) {

  $myPostType = 'product'; /* post type */
  $myTaxononmy = 'product-category'; /* taxonomy */
  $crumbPosition = 2; /* position in the breadcrumbs (0 for first) */

	
  if ( is_singular('product') && taxonomy_exists( $myTaxononmy ) ) {
		
    $productCategories = get_the_terms(get_the_ID(), $myTaxononmy );
		
      if ( !empty ( $productCategories ) ) {
        
        /* get the URL and link text for the new crumb */
        $url = get_term_link($productCategories[0]->slug, $myTaxononmy);
        $text = $productCategories[0]->name;
			
        /* using helper function to build new crumb item */
	$newCrumb = \BricksExtras\Helpers::breadcrumb_item($url,$text);
			
          /* add to the $crumbs array in the position needed */
	  array_splice($crumbs, $crumbPosition, 0, $newCrumb);
			
      }
		
   }

 
  return $crumbs;

});

Now for any products that have a product-category, instead of being output as Home > Product Title, it would output as Home > Product Category Name >  Product Title with the second item being a link to that product category archive page.

This content is restricted to BricksExtras users. Login if you already have an account.