Bug in category name variable and slug

#46440
  • Resolved Jorge
    Rank Math free

    When editing a category, the Rank Math box is showing the wrong category name for the variable %category%. All my categories show the category name of same category, the one that has the higher ID number. As a result, the SEO analysis doesn’t work for the categories.

    I see that the preview slug is wrong as well.

    -My WordPress is installed at http://www.domain.com/staging/
    -My category slug is ‘seccion’
    -The displayed slug is http://www.domain.com/stagingseccion/categoryslug

    I think this problem with the slugs preview appears on some other previews as well.

    • This topic was modified 4 years, 4 months ago by Jorge.
Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    ​​​​​​​

    Jorge
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Todd
    Rank Math free

    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.

    Jorge
    Rank Math free

    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!

    Todd
    Rank Math free

    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.

    Jorge
    Rank Math free

    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, 4 months ago by Jorge.
    Todd
    Rank Math free

    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.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this ticket.