One of the really useful features built into WooCommerce allows the customer to see where they are in the store and then click on a link and go back to a previously visited page. In the programming world, these are called breadcrumbs.
There are several hooks you can use to customize the breadcrumbs to your liking. We'll be using a little code snippet to change what the actual code looks like.
Make sure you have a product in your store and that it's in a product category. That way, you can see the breadcrumbs.
We'll need a little snippet of code to change the breadcrumb separator. We will also need to look up the HTML entity for the character we want to use. If you don't know what an HTML entity is, that's fine. Just know that certain characters (such as <
, >
, &
, ©
, and others) can't always be used directly in code. Sometimes, you need to help the computer translate those symbols. First, let's add the function we need.
functions.php
file, located under wp-content/themes/your-theme-name/
, or your custom WooCommerce plugin:// Change the breadcrumb delimeter from '/' to '>' add_filter( 'woocommerce_breadcrumb_defaults', 'woocommerce_cookbook_breadcrumb_delimiter' ); function woocommerce_cookbook_breadcrumb_delimiter( $defaults ) { }
At this point, we have a function, but it's not doing anything. We need to add a bit of logic to the function. Before we do that, we need to know the HTML entity of the character we want to use. We'll be using the >
character. A quick Google search will reveal that the HTML entity for the >
character is >
. Optionally, you can use a website such as http://www.w3schools.com/html/html_entities.asp to find the HTML entity you need. Now that we have the value we need, we put it in our function.
woocommerce_cookbook_breadcrumb_delimiter
function, we just add the following code right after the beginning of the function:$defaults['delimiter'] = ' > '; return $defaults;