Last active
February 9, 2024 13:46
-
-
Save haxmart/4fa7661c84b9d8d9f0976d668b710c06 to your computer and use it in GitHub Desktop.
Yoast SEO Canonical URL override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('wpseo_canonical', 'wpseo_canonical_domain_replace'); | |
function wpseo_canonical_domain_replace($url) | |
{ | |
$domain = 'domain_here'; // this can be loaded from option table if you want admin to set it. | |
$parsed = parse_url(home_url()); | |
$current_site_domain = $parsed['host']; | |
return str_replace($current_site_domain, $domain, $url); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment