Skip to content

Instantly share code, notes, and snippets.

@Mativve
Last active June 29, 2021 10:50
Show Gist options
  • Save Mativve/6a2f1365f93cb76c1de59728a4a26ddc to your computer and use it in GitHub Desktop.
Save Mativve/6a2f1365f93cb76c1de59728a4a26ddc to your computer and use it in GitHub Desktop.
Yoast SEO Show all product category & shop page in product category
<?php
//
// Yoast SEO Show all product category & Shop page in product category
//
function wpseo_show_all_categories( $this_crumbs ){
if( is_product() ){
$last = $this_crumbs[ count($this_crumbs)-1 ];
$terms = get_the_terms( $last['id'], 'product_cat' );
array_pop($this_crumbs);
foreach($terms as $term){
$this_crumbs[] = array(
'url' => get_term_link($term->term_id),
'text' => $term->name,
'id' => $term->term_id
);
}
$this_crumbs[] = $last;
}
if( is_product_category() ){
$last = $this_crumbs[ count($this_crumbs)-1 ];
$id = woocommerce_get_page_id( 'shop' );
$url = get_permalink($id);
$text = get_the_title($id);
array_pop($this_crumbs);
$this_crumbs[] = array(
'url' => $url,
'text' => $text,
'id' => $id
);
$this_crumbs[] = $last;
}
return $this_crumbs;
};
add_filter( 'wpseo_breadcrumb_links', 'wpseo_show_all_categories', 10, 1 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment