Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amboutwe/ab1652f1f7d73f8cf19d80ebe245fc0a to your computer and use it in GitHub Desktop.
Save amboutwe/ab1652f1f7d73f8cf19d80ebe245fc0a to your computer and use it in GitHub Desktop.
There are two sets of code in this gist; one for the Twenty Nineteen theme and another for the Storefront theme. These are to be used as an example as you or your developer may need to modify the code depending on your theme and site needs.
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Replace WooCommerce Breadcrumbs With Yoast Breadcrumbs
* Credit: Mixed
* Last Tested: Oct 09, 2019 using WooCommerce 3.7.1 with Yoast SEO 12.2 on WordPress 5.2.3
* Theme: Storefront v2.5.3
*/
// Remove WooCommerce Breadcrumbs - Storefront
// Credit: https://docs.woocommerce.com/document/customise-the-woocommerce-breadcrumb/#section-4
add_action( 'init', 'wc_remove_storefront_breadcrumbs');
function wc_remove_storefront_breadcrumbs() {
remove_action( 'storefront_before_content', 'woocommerce_breadcrumb', 10 );
}
// Add Yoast Breadcrumbs To Storefront Content Top
// If you see duplicated breadcrumbs, you may need to use a different hook.
// Documentation for Storefront hooks: https://docs.woocommerce.com/document/storefront-hooks-actions-filters/
add_action( 'storefront_content_top','my_yoast_breadcrumb', 20, 0);
if (!function_exists('my_yoast_breadcrumb') ) {
function my_yoast_breadcrumb() {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
}
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Replace WooCommerce Breadcrumbs With Yoast Breadcrumbs
* Credit: Mixed
* Last Tested: Oct 09, 2019 using WooCommerce 3.7.1 with Yoast SEO 12.2 on WordPress 5.2.3
* Theme: Twenty Nineteen v1.4
*/
// Remove WooCommerce Breadcrumbs - Most Themes
// Credit: https://docs.woocommerce.com/document/customise-the-woocommerce-breadcrumb/#section-4
add_action( 'init', 'woo_remove_wc_breadcrumbs' );
function woo_remove_wc_breadcrumbs() {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
// Add Yoast Breadcrumbs to WooCommerce products and taxonomies
// This does not add breadcrumbs to posts, pages, or non-WooCommerce content in most cases.
// If you see duplicated breadcrumbs, you may need to use a different hook.
// Documentation for WooCommerce hooks: https://docs.woocommerce.com/wc-apidocs/hook-docs.html
add_action( 'woocommerce_before_main_content','my_yoast_breadcrumb', 20, 0);
if (!function_exists('my_yoast_breadcrumb') ) {
function my_yoast_breadcrumb() {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment