Hello,
I tried all three code variations described here: https://theme.co/apex/forum/t/breadcrumbs-adding-category-and-blog-page-home-plus-more/27961
add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2);
function post_parent_trail ($crumbs, $args) {
if ( is_singular('post') ) {
$category = get_the_category( get_the_ID() );
if ( count( $category ) > 0 ) {
$crumbs[1]['label'] = $category[0]->name;
$crumbs[1]['url'] = get_category_link( $category[0]->term_id );
unset($crumbs[2]); //to make sure category won't duplicate
}
}
return $crumbs;
}
add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2);
function post_parent_trail ($crumbs, $args) {
if ( is_singular('post') ) {
$category = get_the_category( get_the_ID() );
if ( count( $category ) > 0 ) {
$cat_array = array();
$cat_array[1]['label'] = $category[0]->name;
$cat_array[1]['url'] = get_category_link( $category[0]->term_id );
array_splice($crumbs, 2, 0, $cat_array);
}
}
return $crumbs;
}
add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2);
function post_parent_trail ($crumbs, $args) {
if ( is_singular('post') ) {
unset($crumbs[1]);
}
return $crumbs;
}
It doesn’t work for my site: http://dey.limit8design.com/blogs/denishas-blog/
I use no category base plugin and also added css code to block blog home page display in breadcrumbs:
.blog .x-breadcrumbs :nth-child(2),
.blog .x-breadcrumbs :nth-child(3),
.archive .x-breadcrumbs :nth-child(2),
.archive .x-breadcrumbs :nth-child(3),
.single-post .x-breadcrumbs :nth-child(2),
.single-post .x-breadcrumbs :nth-child(3) {
display: none;
}
I want breadcrumbs look like the following:
home/category-name/post-title
and for categories that have subcategories I want breadcrumbs look like this:
home/category-name/subcategory-name/post-title
Please advise.
Thanks,
Yelena