Breadcrumbs showing wrong post category

Hello,
My breadcrumbs are not showing the correct post category. In my site here, http://pzu.a90.myftpupload.com/
I have a menu item called “IN EVERY ISSUE” and each one has articles in ie, HISTORY MENU has only articles from the post category “history” but when I click on a article on the history page it always says . News & Features. This is the same for any other submenu, they all say “news & features”

any idea why?? I checked and they are not listed under both categories. History is only marked history.

TIA
Rena

Hello There,

Thanks for posting in! To get this exact breadcrumbs structure (Home > Blog Page Home > Category > Post), please add this code snippet in the functions.php file of the child theme directory:

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

Please let us know if this works out for you.

Thank you! Question, does it have to go Home > Blog Page Home > Category > Post
. In my mind it was Home > Category > Post
Is that possible?

1 Like

Hi There,

Please update the previous code to this:

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);
		}
		unset($crumbs[1]);
	}
	return $crumbs;  
}

Hope that helps and thank you for understanding.

1 Like

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