Hello,
Thank you for contacting Rank Math today.
When you have more than 1 category selected, please choose the one you want to show in the breadcrumbs as “Make term primary”
See screenshot: https://i.rankmath.com/HiH2LS
Make sure Primary Category is also select from the drop-down in WordPress Dashboard > Rank Math > Titles & Meta > Products > Product Taxonomy.
In case you still wish to use the code, you can use it as follows:
/**
* Filter to change the primary term output of the breadcrumbs class.
*
* @param WP_Term $term Primary term.
* @param array $terms Terms attached to the current post.
*/
add_filter( 'rank_math/frontend/breadcrumb/main_term', function( $current_term, $terms ) {
return $current_term;
}, 10, 2 );
You also need to have this option enabled in the breadcrumbs settings already.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thanks for the feedback.
Primary Category is selected in Titles & Meta > Products > Product Taxonomy
“Show Categories” option is enabled in the breadcrumbs settings
“When you have more than 1 category selected, please choose the one you want to show in the breadcrumbs as “Make term primary””
— this is not possible with 7000+ products
If I’ve understood this correctly, when more than 1 category selected for a product, the following code will automatically assign the taxonomy term from hierarchy root as the Primary Term (i.e not the child term)
add_filter( 'rank_math/frontend/breadcrumb/main_term', function( $current_term, $terms ) {
return $current_term;
}, 10, 2 );
I’m specifically looking for code to automatically assign Primary Term to the ‘lowest’ child term in the product category hierarchy.
For example, in the following category structure, Guitar Sides should be automatically set as primary term:
Pre-cut Sizes > Instrument Wood > Guitar Sides
Many thanks for the assistance!
Hello,
Thank you for getting back to us.
If this is the option you require have you tried using the bulk options to make editions for a primary category?
This would be the best way to go about this by using the quick edit features and edit the posts like that.
It’s faster than opening the posts themselves.
Please let us know if that method works for you.
Thank you.
Thanks for the suggestion Brian, but in our scenario it isn’t practical as we’re frequently processing bulk product imports with stock changing regularly.
Is there a code solution to achieve this along the lines of the snippet provided, but targeting the lowest product sub-category and not the product root category?
Hello,
Thank you for the update.
I’m sorry to say that we don’t have a filter that can change the primary category on all products to be the child category selected.
The quick way to do this without needing to open the product page is the step provided by my colleague above, which is available with our PRO version.
I hope that helps.
Thank you, and please don’t hesitate to contact us anytime if you need further assistance with anything else.
Thanks for the feedback and looking into the query. Understood that pro version is required to access the recommended bulk options tool for completing this process.
Appreciate all the hard work that goes into creating and maintaining such an excellent plugin. Really well done!!
Hello,
Glad that helped.
Please feel free to reach out to us again in case you need any other assistance.
We are here to help.
Thank you.