Blog URL change in breadcrumbs for post archives

Hi, I wonder if you can help me expand on this code that I found in your forums. https://theme.co/apex/forum/t/breadcrumbs-with-custom-blog-page/47130/4

It alters the breadcrumbs on single post pages so the Blog URL is set to a custom page. This is great but can this be applied also to post category archives but not product category archives?

add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2);

function post_parent_trail ($crumbs, $args) {
	if ( is_singular('post') ) {

		$post_ID  = 3433;					
		$post_array = array();
		$post_array[1]['label'] = get_the_title( $post_ID );
		$post_array[1]['url'] = get_permalink( $post_ID );
		array_splice($crumbs, 2, 0, $post_array);

		unset($crumbs[1]);
	}
	return $crumbs;  
}

Thanks

Hi @seepops,

In this case, please try with this code:

add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2);

function post_parent_trail ($crumbs, $args) {
	if ( is_singular('post') || is_category() ) {

		$post_ID  = 3433;					
		$post_array = array();
		$post_array[1]['label'] = get_the_title( $post_ID );
		$post_array[1]['url'] = get_permalink( $post_ID );
		array_splice($crumbs, 2, 0, $post_array);

		unset($crumbs[1]);
	}
	return $crumbs;  
}

Hope that helps and thank you for understanding.

Hey @thai that worked perfectly. Thank you for your quick help.

You’re always welcome @seepops!

Cheers.

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