Canonical tag – wrong address

#156728
  • Resolved John David Lythgoe
    Rank Math free

    Hi there,

    I like Rank Math a lot, but it’s sometimes hard to figure out what I have to not do of what I did before I used it, so as not to duplicate with it.

    I have an issue that resembles a previous one you dealt with.

    I am using Generatepress on TwentyTwenty. I have a dual-language site, English (primary) and Serbian. I intend to add more languages later. Before using Rank Math I used self-referring canonical tags on each page.

    Now, I found that Rank Math sets canonical tags, and does it right for all pages except the Serbian home page, which it refers to the English one. Since I don’t want visitors, especially search engines, who visit the Serbian home page to be told that the English one is canonical, I have placed a filter so that Rank Math does not add a canonical tag to the Serbian home page.

    However, Rank Math seems to be preventing me from setting my own tag with the correct address.

    Can you tell me what I can do about this?

    Thanks,
    David

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay and for any inconvenience this issue may have caused you.

    I’ve checked your account, and it seems that there are two websites added, the .com which is for your English (main) website, and the .rs for your Serbian site. Could you confirm if you are referring to that as I’ve checked on your main site, there’s also a .com/sr/ version?

    You can also add the affected URL/s in the designated Sensitive Data section to further check this issue.
    Sensitive Data Section

    It is completely secure, and only our support staff has access to that section.

    I hope that helps. Thank you, and looking forward to your update.

    Hello,

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

    Thank you.

    Hello,

    If you wish for your pages to have the canonical tag, I would not recommend having the canonical tag removed via the filter. The filter overrides any canonical setting you may set on your site.

    Instead of having the filter remove the canonical, you can use a condition to check your page and add a canonical URL that you wish to have instead.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Yes, I tried that, but I couldn’t get the syntax right. Can you give me a hand with it?

    And do you have any idea why Rank Math places the wrong reference, just on that page?

    Thanks!

    Hello,

    You can use the page id of the page you have set as your translated homepage to add the canonical as follows:

    
    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	if(is_page( 11 )){ //replace 11 with the page id
    	$canonical = 'https://yourdomain/sr/';
    	return $canonical;
    	}
    	return $canonical;
    });
    

    Would you please confirm you have not added a custom canonical under the advanced tab of Rank math meta box on the page? If not, it may have something to do with your settings.

    Let us know how this goes.

    BTW, the &#8221 in the above mesage was added by your reply app, I didn’t mean it to be there.

    Dear Michael,

    Thanks for this. I tried it, but it does not seem to make any difference. Rank Math still returns
    <link rel=”canonical” href=”https://halifax-translation.com/&#8221; />
    which is the same as for the English home page, instead of
    <link rel=”canonical” href=”https://halifax-translation.com/sr/prevodilacka-agencija-beograd&#8221; />
    which is the Serbian home page address.

    Now you draw my attention to the Rank Math Advanced box, I can see that it has the correct canonical address there (that is not something I have done).

    By the way, I am placing this in the theme’s functions.php file. Is there any other option that would not be removed on updating the theme?

    Hello,

    Thank you for the update, and sorry for the delay.

    About your last question, you can use the Code Snippets plugin for the filters to be still intact even upgrading your theme. The snippets are stored in the WordPress database, independent of the theme and unaffected by WordPress upgrades.

    If the issue still persists, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    Thank you, and we really look forward to helping you.

    Thanks for the plugin suggestion – this works! I put your code in the Code Snippets, and the canonical tag is now the right one.

    Now why would it work here, and not in the functions.php file? And why does Rank Math get just this one wrong to start with? Mysteries, but in practice it is now right.

    Many thanks to you guys. Where can I give you 5 stars?

    Hello,

    It could be that there are other functions in the functions.php file that is obstructing the custom filter you are trying to add. Just do make sure are inserting the code at the bottom of the file.

    Since the filter works now with the help of Code Snippets plugin, you can safely leave it like that as putting it in the functions.php will remove the code if you are to update the theme.

    With that said, we are so glad that your issue has been resolved. You could leave us a review here. We appreciate your time and patience.

    If you 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.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Canonical tag – wrong address’ is closed to new replies.