rel=canonical tag links not to original post (duplicate content)

#95584
  • Resolved Achim
    Rank Math free

    Hi,

    we use RankMath in combination with WPML. Blog posts are written in English only, and other language versions of the site will also display them in English (WPML post setting: use translation if available or fallback to default language). So there are no translations of the posts (also no duplicates). WPML adds the hreflang attributes correctly but the rel=canonical attribute of RankMath always links to the current page.

    Example:

    • /blogpost (english, original)
    • /en/blogpost (english, not really existing, managed by WPML)
    • /fr/blogpost (english, not really existing, managed by WPML)

    When I now visit /de/blogpost, the canonical link is /de/blogpost and not /blogpost as it should be.

    What can I do so that the canonical link points to the right page?

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 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 your site URLs in the sensitive section?

    You should also check your hreflang attributes and your content language set in your translated URLs: <meta property="og:locale" content="en_US" /> This should reflect the required translation and if not it is the likely cause of the duplicate content issue on your site. Here is a google support thread you can check on this: https://support.google.com/webmasters/thread/8001769?hl=en

    If you still want to change your cacnonical URLs, you can edit the indvidual translated pages and change this under the Advanced tab of Rank math meta box.

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Achim
    Rank Math free

    Hello,

    I have updated the sensitive data as requested.

    The hreflang attributes seem to be set correctly – also og:locale (in the current language).

    Thanks also for the link to the Google Support Thread, but this problem does not apply to us because we do not redirect automatically.

    Finally, the canoncial URL should always be identical in all languages (english version), since all other versions do not exist, but are only output by WPML as a fallback (so that the blog modules in other languages are not empty). However, the canoncial URL always corresponds to the current language (e.g. /de/…, /fr/…), which leads to duplicated content.

    Manually I can’t change the canonical URLs either, because the translations don’t exist in WordPress.

    I can only think of a solution via functions.php, where I remove the language variables from $canonical. This seems to me to be quite cumbersome and I was sure that this problem should affect others as well.

    Thank you.

    • This reply was modified 3 years, 5 months ago by Achim.
    Achim
    Rank Math free

    Update:
    Here’s the function I created as a workaround. All languages will get the canonical link from the original language if no translation exists. Otherwise the translated link will be used.

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    
        $is_translated = apply_filters( 'wpml_element_has_translations', NULL, get_the_ID() );
        
        if(!$is_translated) {
    
            $originalPost = get_permalink( get_the_ID() );
            $originalPost = str_replace('/'.ICL_LANGUAGE_CODE, '', $originalPost);
            
            if ( $originalPost ) {
                $canonical = $originalPost;
            }
        } 
        
    return $canonical;
    });

    Hello,

    We are glad you were able to resolve your issue.

    Do you wish us to close this thread or troubleshoot this further?

    If you have any further question(s), please let us know. Thank you.

    Achim
    Rank Math free

    Hi,

    this thread can be closed, thanks!

    Alberto
    Rank Math business

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    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.

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

The ticket ‘rel=canonical tag links not to original post (duplicate content)’ is closed to new replies.