I am using Breadcrumb NavXT and Filter Everything. I am trying to add the product category name to the trail for a custom archive page (not taxonomy archive) I was able to do something utilizing breadcrumb author’s example (https://mtekk.us/archives/guides/add-a-static-breadcrumb-to-the-breadcrumb-trail/) and filter author's function. Here is my code: add_action('bcn_after_fill', 'my_static_breadcrumb_adder'); function my_static_breadcrumb_adder($breadcrumb_trail) { $output = flrt_selected_filter_terms(); $w1 = array_keys($output)[0]; $x1 = $output[$w1]["values"][0]; $y1 = get_term_by('slug', $x1, 'product_cat'); $z1 = $y1->name; if (isset($z1)) { $new_breadcrumb1 = new bcn_breadcrumb($z1, NULL, array('home'), get_site_url() . '/e-shop/' . $w1 . '-' . $x1, NULL, true); array_splice($breadcrumb_trail->breadcrumbs, -4, 0, array($new_breadcrumb1)); } } My only problem is that I cannot add the extra trail part to schema.org data (itemListElement->name). Still shows ‘E-SHOP’. It should be the category name.
Jese Leos
September 19, 2024
Verified user
We can achieve the expected output by adding the custom breadcrumb to the breadcrumb trail and also updating the schema.org data. add_action( 'bcn_after_fill', 'my_static_breadcrumb_adder' ); function my_static_breadcrumb_adder($breadcrumb_trail) { $output = flrt_selected_filter_terms(); if ( empty( $output ) ) { return; } $w1 = array_keys( $output )[0]; $x1 = $output[$w1]['values'][0]; $y1 = get_term_by( 'slug', $x1, 'product_cat' ); $z1 = $y1->name; if ( isset( $z1 ) ) { $new_breadcrumb1 = new bcn_breadcrumb( $z1, NULL, array('taxonomy', 'product_cat' ), get_term_link( $y1 ), NULL, true ); array_splice( $breadcrumb_trail->breadcrumbs, -1, 0, array( $new_breadcrumb1 ) ); // Here we have updated schema.org data. $position = count( $breadcrumb_trail->breadcrumbs ); $breadcrumb_trail->add( new bcn_breadcrumb( $z1, NULL, array( 'taxonomy', 'product_cat' ), get_term_link( $y1 ), NULL, true, $position ) ); } }