Breadcrumbs : Custom Post Type (PRO)

Hi,

Looks like there has been changes to the way how Breadcrumbs are displayed and x_breadcrumbs() function has been deprecated. With Pro - I have added Breadcrumb element in the Footer and it does display the breadcrumb as

Home > Custom post type item name

I would like it to display as Home > Custom Post Type > Custom post type item name

How do I go about doing this?

Thanks in advance.

Hi @dshakya ,

Thanks for posting in.

It still x_breadcrumbs() what changed is the coding within it. It’s now more complex and customizable through the filter. Please check this https://theme.co/apex/forum/t/modify-the-breadcrumb-element/24923/4.

There is no specific answer since the coding depends on your current setup where crumbs indexes could be different. But what you need to do is push your own breadcrumbs to breadcrumbs data array. Utilizing the var_dump( $crumbs ) function will help you what’s in the array and there, you can decide the structure and how you’ll change it.

Thanks!

Hi @Rad,

Thanks for replying. Following the referenced thread, I can change the the label for a particular crumb. What I would like to do is - If a custom post type is “B”, I would like to add a crumb which is the custom post type “A” essentially making it look like A is the parent of B.

So: Home > A > B

Currently, I get Home > B and I can customise that label B to anything I was using your reply reference. Any help is appreciated.

Hi there,

You have to know the structure of your current breadcrumbs array first using var_dump( $crumbs ). Example,

function my_custom_breadcrumbs( $crumbs, $args ) {

 var_dump( $crumbs );

  return $crumbs;

}

add_filter( 'x_breadcrumbs_data', 'my_custom_breadcrumbs', 10, 2 );

Then load that page and copy the outputted array, it will be your reference. Let’s say, the $crumbs[0] is home, then $crumbs[1] is taxonomy, then there is $crumbs[2] post type URL. That’s just a sample, but based on the outputted structure, let’s say you wish to add more, then you’ll have to create and add your own structure. Like this

function my_custom_breadcrumbs( $crumbs, $args ) {

  if ( get_post_type () == 'post_type_A' ) {

       //Override the existing $crumbs[2]

       $crumbs[2]['label'] = get_the_title();
       $crumbs[2]['url'] = get_permalink();

       //Or add new

       $crumbs[3]['label'] = 'Awesome Title';
       $crumbs[3]['url'] = 'Awesome URL';


  }

  if ( get_post_type () == 'post_type_B' ) {
       
       $crumbs[2]['label'] = 'A title from post type A';
       $crumbs[2]['url'] = 'A URL from post type A';   
       $crumbs[3]['label'] = get_the_title();
       $crumbs[3]['url'] = get_permalink();   
    
  }

  return $crumbs;

}

add_filter( 'x_breadcrumbs_data', 'my_custom_breadcrumbs', 10, 2 );

It’s all about array, it depends if you’ll override the existing, or add new, there is no limitation. That’s just a sample as I don’t understand what you’re trying to achieve with post type A and B, they are different post types so there are no relationship. Only same post type could have parent and child relationship. I recommend contacting a developer.

Thanks!

Thank you so much for pointing to right direction. This helps a lot.

What I am trying to achive is something like - I have custom post types -

  1. Catchment
  2. Subcatchment
  3. Site

These are nested like Catchment > Subcatchment > Site

So when a particular site is displayed using template file - single-site.php, I would like to have the parent catchment and subcatchment in the breadcrumb.e.g.

Catchment 1 > Subcatchment 5 > Site 10

Would be good to work our the parent-child relationship between different post types. I know Toolset is able to map it but hoping there is a better of doing it without investing in Toolset.

Hi,

While we are happy to help with the occasional quick tweak here or there, we are well into the custom development realm, which is outside the scope of support we can offer. If you need more in depth changes, you may wish to consult with a developer. X is quite extensible with child themes, so there are plenty of possibilities. Thanks for understanding.

Thanks @paul.r! I totally understand. I will try and get further help elsewhere and see if there are any plugins out there that will allow this to be done.

You’re welcome! :slight_smile:

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