Link to a Page Rather Than the Category Archive in a Breadcrumb

A topic that frequently comes up in the support forums is how to have a breadcrumb representing a category link to a Page (instance of the Page post type) rather than a category archive. Since this is not natively supported by WordPress, Breadcrumb NavXT does not natively support it. However, there is a filter that can facilitate this behavior.

The presented solution is a simplistic example for a single category. However, it can be extended for multiple categories, or taxonomy terms. Finally, rather than being hard-coded, the IDs could come from a term_meta field.

The Code

add_filter('bcn_breadcrumb_url', 'my_breadcrumb_url_changer', 3, 10);
function my_breadcrumb_url_changer($url, $type, $id)
{
	if(in_array('category', $type) && (int) $id === MYCATID)
	{
		$url = get_permalink(PAGEID);
	}
	return $url;
}

After placing this code into your site specific plugin, you will need to update two portions of it. Replace MYCATID with the ID of the category you want to change the link on, and replace PAGEID with the page you wish for the breadcrumb to link to. That’s it. Simple, right?

-John Havlik

[end of transmission, stay tuned]

Posted in Guides
Updated:

4 thoughts on “Link to a Page Rather Than the Category Archive in a Breadcrumb

  1. Thank you so much!!
    Your explanation was easy and very much to the point of what I really needed to know.
    Awesome plugin!!

  2. Hello, would you be so kind as to tell me in which file I have to put this code and if I have to repeat it completely for each category that I want to change.
    Thank you.

Comments are closed.