Skip to content

Instantly share code, notes, and snippets.

@haxmart
Last active February 9, 2024 13:46
Show Gist options
  • Save haxmart/4fa7661c84b9d8d9f0976d668b710c06 to your computer and use it in GitHub Desktop.
Save haxmart/4fa7661c84b9d8d9f0976d668b710c06 to your computer and use it in GitHub Desktop.
Yoast SEO Canonical URL override
<?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