Breadcrumbs to show "parent category" in hierarchy listing

Hi there,

I was able to cause the breadcrumbs on my site to display the “category” of each post using thesome code provided by @Thai on this ticket.

This works great! However, I would also like it show the “parent category” of the current category of the current post. How can I achieve this?

What I am currently seeing: Home > Category > Post
What I would like to see: Home > Parent Category > Category> Post

Thank you so much!

-Joshua

Hey Joshua,

That is technically possible. However, that would fall beyond the scope of our support since it would require custom development.

Thank you for understanding!

Really? Hmm…

I understand, but I would assume that it is the default behavior for the breadcrumbs to reflect the URL page hierarchy.

If the URL is - Home / Parent Category / Category / Post Name
then shouldn’t the breadcrumbs reflect that? It does so everywhere else on the website. It’s only on our “Posts” that the parent category is not included in the breadcrumbs hierarchy…

I’m not sure why?

-Josh

Hello Josh,

Thanks for updating the thread.

Displaying parent category in breadcrumb will require some custom development work. I suggest you to please take a look at following threads for some solutions:

https://wordpress.org/support/topic/breadcrumbs-on-pages-not-showing-the-parent-child-structure-anymore/

Thanks.

Hi again,

Thank you for those links you recommended. I have a quick question, in the first link you provided there is a recommended solution. Would I add this to my functions.php in addition to the code I already put to display the “category”? Or would that replace the original code I am using (provided by Thai on this ticket)?

Thank you,

Joshua

Hello Joshua,

You will have to integrate the code in the existing code in your child theme’s functions.php.
You might want to check out this other threads as well:

Hope this helps.

Thanks for the links… I still cannot figure this out. I know that it’s possible, but I simply lack the php knowledge.

This is the code I’m using to display Home > Category > Post. Is there some kind of alteration/change I can make to also include the “Parent Category?”

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

Hi @SeekGod,

Our staffs provided to your many solutions. If you still need to help on this, you need to consult a 3rd party developer.

Thanks for understanding!

For the record @Thai, this should be considered a theme FLAW on YOUR end since the breadcrumbs are not showing the full path like they should.

Since your breadcrumbs are not showing the full path I will have to use a third party plugin. My question now is which file do I place the code to display the breadcrumbs, if I want them to display at the bottom of every Post? Which X/Pro theme file creates the single Post template?

Please answer me this.

Just to clarify, I have this code snippet to display breadcrumbs from Yoast. I just want to know which Pro theme file should I paste it in to show the breadcrumbs at the bottom of every Post?

<?php
if ( function_exists('yoast_breadcrumb') ) {
  yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>

Hi @SeekGod,

You can add the following code under functions.php file locates in your child theme:

add_action( 'x_after_view_global__content', 'x_print_author' );
function x_print_author(){
	if( is_singular( 'post' ) ){
		if ( function_exists('yoast_breadcrumb') ) {
			yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
		}
	}
}

If you want anything else, feel free to create another ticket.

Thank you.

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