Issue with breadcrumbs

Hi,
I’ve put breadcrumbs on all of the posts in our site. However, for some reason the breadcrumbs are showing the list as: Home -> Blog -> Name of post. We want it to be Learning Center -> Category -> Name of post. Can you help me understand how to do that?

Thanks!

Hello There,

Thanks for posting in! The breadcrumbs will display the default which is Home -> Blog -> Name of post. If you want to include a category in your breadcrumb, please check out this thread: https://theme.co/apex/forum/t/pro-child-breadcrumbs-with-category-where-is-breadcrumbs-php/22940/6

The link mentions Pro theme. The solution will also apply in X theme.

Hope this helps.

Thanks. So just to make sure I understand, if I paste the text in the functions.php I will have the format:
Learning Center -> Category -> Name of post?

Hi There,

You have to set the page for the posts page first under Settings > Reading:

And also change the title of that page to Learning Center.

After that adding this custom code under functions.php file locates in your child theme:

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;
}

Hope it helps :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.