How to Add a Custom Breadcrumb Home URL in Woocommerce

Home » Snippets » How to Add a Custom Breadcrumb Home URL in Woocommerce
0

Created with:

Visibility: 

public

Creator: Alex

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

WooCommerce is a popular platform for building e-commerce websites, allowing businesses to sell products and services online. One important aspect of any e-commerce website is navigation, and breadcrumbs are a crucial part of that. Breadcrumbs are a type of secondary navigation that shows the user where they are on the website and how they got there, making it easier for them to navigate and find what they’re looking for. In this article, we’ll show you how to add a custom breadcrumb home URL in WooCommerce and improve your site’s user experience.

					function wpturbo_add_custom_breadcrumb_home_url( $crumbs ) {
  $home_url = 'https://www.yourcustomhomepage.com/'; // change this to your custom home URL
  array_unshift( $crumbs, '<a href="' . $home_url . '">' . __( 'Home', 'wpturbo' ) . '</a>' );
  return $crumbs;
}
add_filter( 'woocommerce_get_breadcrumb', 'wpturbo_add_custom_breadcrumb_home_url' );
				

In this article, we will learn how to add a custom breadcrumb home URL in WooCommerce. A breadcrumb is a navigation aid that helps users understand where they are on a website. In WooCommerce, you can add breadcrumbs to help customers navigate the store.

The code snippet above provides a function called wpturbo_add_custom_breadcrumb_home_url() that modifies the breadcrumb list in WooCommerce. The function takes an array of breadcrumbs as an argument and returns an updated array of breadcrumbs that includes the custom home URL.

function wpturbo_add_custom_breadcrumb_home_url( $crumbs ) {

The first line of the snippet defines the function and provides an argument $crumbs. $crumbs is an array of breadcrumbs generated by WooCommerce.

$home_url = 'https://www.yourcustomhomepage.com/'; // change this to your custom home URL

In the second line, we define a variable $home_url and assign it the custom home URL. You should replace 'https://www.yourcustomhomepage.com/' with the actual URL that you want to use.

array_unshift( $crumbs, '<a href="' . $home_url . '">' . __( 'Home', 'wpturbo' ) . '</a>' );

The next line is where the real magic happens. We use the array_unshift() function to add a new breadcrumb to the beginning of the array. The new breadcrumb is an anchor tag (<a>) that links to the custom home URL. The text of the link is what will be displayed in the breadcrumb. In this case, we are using the string 'Home'.

return $crumbs;

Finally, we return the updated array of breadcrumbs.

add_filter( 'woocommerce_get_breadcrumb', 'wpturbo_add_custom_breadcrumb_home_url' );

The last line hooks the wpturbo_add_custom_breadcrumb_home_url() function into the woocommerce_get_breadcrumb filter. This ensures that the updated breadcrumb list is displayed on the website. Now when customers navigate your store, they will see the custom home URL included in the breadcrumb navigation.

Register an account to save your snippets or go Pro to get more features.