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 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.
2
Answers
I reply to this thread of mine with a different issue for the same snippet. After several revisions of the code, it now works as expected, however PHP produces a warning which I would like to resolve.
The part in question is the following:
It looks as when the bcn object is created, PHP complains:
We can achieve the expected output by adding the custom breadcrumb to the breadcrumb trail and also updating the schema.org data.