Skip to content

Instantly share code, notes, and snippets.

@sybrew
Last active March 20, 2024 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sybrew/7a5d0b0dc5797187301172d60e7dd170 to your computer and use it in GitHub Desktop.
Save sybrew/7a5d0b0dc5797187301172d60e7dd170 to your computer and use it in GitHub Desktop.
Removes WooCommerce's shop base from The SEO Framework's breadcrumbs.
<?php
// Don't include the PHP opening tag if PHP is already open.
add_filter(
'the_seo_framework_breadcrumb_list',
function ( $list, $args ) {
if ( isset( $args ) ) {
if ( 'single' === \The_SEO_Framework\get_query_type_from_args( $args ) ) {
$is_product = tsf()->query()->is_product( $args['id'] );
}
} else {
$is_product = tsf()->query()->is_product();
}
if ( $is_product ?? false ) {
$shop_url = tsf()->uri()->get_bare_pta_url( 'product' );
}
if ( ! empty( $shop_url ) ) {
foreach ( $list as $position => $item ) {
if ( $shop_url === $item['url'] ) {
unset( $list[ $position ] ); // Remove URL item.
$list = array_values( $list ); // Reset positions.
break;
}
}
}
return $list;
},
10,
2,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment