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”
Make sure Primary Category is also select from the drop-down in WordPress Dashboard > Rank Math > Titles & Meta > Products > Product Taxonomy.
If yu still wish to use the code, you can use it as follows:
add_filter( 'rank_math/frontend/breadcrumb/main_term', function( $current_term, $terms ) {
global $post;
$terms = get_the_terms( $post, 'category' );
if ( ! empty( $terms ) ) {
return $terms[0];
}
return $current_term;
}, 10, 2 );
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thanks for your answer @Michael Davis, it really works, but like in the example you have provided the parent category is selected by default, and I want the last child to be selected by default, (Hoodies) in the picture you provided not (Clothing), any suggestions?
Hello,
Just to be sure, do you mean you want whenever you add a new product, to have that children selected as primary? Or not only with new products but with all the ones already added?
Looking forward to help you.
Hi, Yes I mean every time a new product added the last child is selected as primary
Thanks @Alberto
Managed to fix it with a new variable for new and old posts, copied and edited this function, Thanks
add_action( ‘rank_math/vars/register_extra_replacements’, function() {
rank_math_register_var_replacement(
‘childCat’,
[
‘name’ => esc_html__( ‘last child Category’, ‘rank-math’ ),
‘description’ => esc_html__( ‘Category last child’, ‘rank-math’ ),
‘variable’ => ‘childCat’,
‘example’ => MY FILTER NAME(),
],
‘MY FILTER NAME’
);
Hello,
We are glad you were able to find a way to fix your issue.
Do you wish to close this thread as resolved?
If you have any further question(s), please let us know. Thank you.
Hello,
We are super happy that your issue is resolved.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.