Created
August 3, 2018 05:10
-
-
Save davevanhoorn/12def715575dafc35f6c008b76bd9d61 to your computer and use it in GitHub Desktop.
Remove "Products" from Yoast SEO breadcrumbs in WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** Paste in functions.php | |
** Remove "Products" from Yoast SEO breadcrumbs in WooCommerce | |
*/ | |
add_filter( 'wpseo_breadcrumb_links', function( $links ) { | |
// Check if we're on a WooCommerce page | |
// Checks if key 'ptarchive' is set | |
// Checks if 'product' is the value of the key 'ptarchive', in position 1 in the links array | |
if ( is_woocommerce() && isset( $links[1]['ptarchive'] ) && 'product' === $links[1]['ptarchive'] ) { | |
// True, remove 'Products' archive from breadcrumb links | |
unset( $links[1] ); | |
} | |
// Rebase array keys | |
$links = array_values( $links ); | |
// Return modified array | |
return $links; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code worked perfect for me! (I used Code Snippets to implement it as I'm a complete beginner). Thanks for sharing this.