0

On this url: https://www.phuket-luxury-villas.us.com/tourist-spots/buddhist-temples-wats/ I have a wrong canonical link:

<link rel="canonical" href="https://www.phuket-luxury-villas.us.com/tourist-spots/buddhist-temples-wats/" />

It used to be the follow canonical link:

<link rel="canonical" href="https://www.luxuryvillasphuketthailand.com/tourist-spots/buddhist-temples-wats/" />

I tried to use this code:

function yoast_seo_canonical_change_woocom_shop( $canonical ) { if ( is_archive() ) { echo ''; } } add_filter( 'wpseo_canonical', 'yoast_seo_canonical_change_woocom_shop', 10, 1 );

But it seems that is put now too many canonical links on the website...

Any idea what else I can do?

This mentioned url, is an archive (done with Toolset). And we are using WPML. Sadly WPML won't let us to duplicate categories or taxonomies

1
  • 2
    It sounds like you need to determine where all the canonical tags are coming from. I'd suggest disabling Yoast temporarily, clearing cache if needed, and checking to see if a canonical is still on the page. If so, then Yoast may not be what you need to adjust. But if the canonical is gone you'll know it's Yoast. I do know that their filters usually expect a return rather than an echo, so you could try changing the command, but the filter may not accept an empty string at all.
    – WebElaine
    Commented Nov 12, 2019 at 16:46

1 Answer 1

1

I found the solution by myself:

function yoast_seo_canonical_change_archives( $canonical ) {
    if ( is_tax( 'tourist-spots' ) ) {
    $path = parse_url( $canonical, PHP_URL_PATH );
    return 'https://www.luxuryvillasphuketthailand.com' . $path;
    }
    return $canonical;
}
add_filter( 'wpseo_canonical', 'yoast_seo_canonical_change_archives', 10, 1 );
1
  • 1
    There's no reason Yoast's would be incorrect unless there was already something like this that was making it incorrect. Check existing code and the settings first. Commented Nov 13, 2019 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.