Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
Could you please share a link to one of the affected categories via the sensitive data section so that we can check this further?
Looking forward to helping you. Thank you.
βββββββ
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Hi,
Thank you for helping in reproducing the error. As it was an edge case, we did not test it.
It should be fixed in one of the upcoming updates.
For now, please add the following code in your themeβs functions.php file to fix the issue:
add_filter( 'term_link', function( $link, $term, $taxonomy ) {
if ( 'product_cat' !== $taxonomy ) {
return $link;
}
$permalink_structure = wc_get_permalink_structure();
$category_base = trailingslashit( $permalink_structure['category_rewrite_slug'] );
$link = str_replace( $category_base, '', $link );
return $link;
}, 0, 3 );
Hope that helps. Thank you.
Hi,
Unfortunately, I added the code but it didn’t fix the issue. I even put it at the top of functions.php to make sure.
Thanks!
Hi Jorge,
The First issue, please use %term%
instead of %category%
The %category%
variable is to be only used on single posts – not the category archive itself.
For the second issue, we have logged it as a bug and it only happens in the backend preview – the actual URLs should work fine. We are working on a fix and we will release an update soon.
Thank you.
FYI, the front end is working just fine with %category%
, the page title does display the correct category name. I can see that %term% fixes the issue in the backend as well. I’m not sure if I put %category%
there manually or if it got imported from AIOSEO.
However, if %category%
won’t work here, that’s not what Rank Math says when describing the variable.
In the dropdown with all the variables, the description for %category%
it says it will pick up the first category of the post “OR the current category in the category archives” (I’m translating the description from Spanish so it might not be 100% accurate).
So – is the description wrong, or is there a bug with the variable?
I haven’t found another instance of the canonical URL preview bug although I’m pretty sure I had seen it somewhere else. I’ll report if that’s the case.
Thanks a lot for the assistance!
-
This reply was modified 4 years, 6 months ago by Jorge.
Hi Jorge,
The description we used is correct. It is just supposed to be used on single posts to show the category assigned to them in the title or meta description.
%category% on Single post
%term% on category archives.
That’s how it works.
We are glad it is all good and working with the term variable.
Thank you.