Breadcrumbs

Last updated 3 months ago

Start with Yoast SEO Breadcrumbs, but fallback to Jetpack.

PHP
if ( function_exists( 'yoast_breadcrumb' ) ) {

	// WordPress SEO Breadcrumb.
	yoast_breadcrumb( '<p id="breadcrumbs" class="breadcrumbs" aria-label="breadcrumb">', '</p>' );


} elseif ( function_exists( 'jetpack_breadcrumbs' ) ) {

	// Jetpack Breadcrumbs.
	jetpack_breadcrumbs();

}

WooCommerce: Rename Home:

PHP
/**
 * Rename "home" in breadcrumb
 */
function hlabs_change_breadcrumb_home_text( $defaults ) {
    // Change the breadcrumb home text from 'Home' to 'Apartment'.
    $defaults['home'] = 'Apartment';
    return $defaults;
}
add_filter( 'woocommerce_breadcrumb_defaults', 'hlabs_change_breadcrumb_home_text' );
PHP
/**
 * Change the breadcrumb separator
 */
add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_delimiter' );
function wcc_change_breadcrumb_delimiter( $defaults ) {
	// Change the breadcrumb delimeter from '/' to '>'
	$defaults['delimiter'] = ' &gt; ';
	return $defaults;
}
PHP
/**
 * Change several of the breadcrumb defaults
 */
add_filter( 'woocommerce_breadcrumb_defaults', 'jk_woocommerce_breadcrumbs' );
function jk_woocommerce_breadcrumbs() {
    return array(
            'delimiter'   => ' &#47; ',
            'wrap_before' => '<nav class="woocommerce-breadcrumb" itemprop="breadcrumb">',
            'wrap_after'  => '</nav>',
            'before'      => '',
            'after'       => '',
            'home'        => _x( 'Home', 'breadcrumb', 'woocommerce' ),
        );
}
PHP
/**
 * Replace the home link URL
 */
add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
function woo_custom_breadrumb_home_url() {
    return 'http://woocommerce.com';
}
PHP
/**
 * Remove the breadcrumbs 
 */
add_action( 'init', 'woo_remove_wc_breadcrumbs' );
function woo_remove_wc_breadcrumbs() {
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}

All code snippets are licensed GPLv2 or later unless otherwise stated.