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]
Thank you so much!!
Your explanation was easy and very much to the point of what I really needed to know.
Awesome plugin!!
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.
Hi Ramon,
As stated in the article, this code should go into a site specific plugin (a simple plugin with site specific code). Yes, you have to manually add the page to category mappings for each page<->category relationship you wish to establish. Note that Breadcrumb NavXT Paths (a premium extension to Breadcrumb NavXT) provides a GUI interface for doing this (https://mtekk.us/extensions/breadcrumb-navxt-paths/#jp-carousel-9133).
-John Havlik
I use this theme: https://wordpress.org/themes/magazina/ and I tried to copy this code and create a plugin to install it, but after doing it nothing happens, the breadcrumb always refers to the category and not to the page indicated in the code id .. why?