Skip to content

Instantly share code, notes, and snippets.

@itsHall
Last active October 15, 2021 16:21
Show Gist options
  • Save itsHall/32d1f4493104705969207ff77c67049f to your computer and use it in GitHub Desktop.
Save itsHall/32d1f4493104705969207ff77c67049f to your computer and use it in GitHub Desktop.
Replace Domain Name In Yoast SEO Canonical URL (Flywheel Local Bug Fix)
<?php
//------------------------------------------------//
// Replace Domain Name In Yoast SEO Canonical URL //
//------------------------------------------------//
$liveSiteURL = 'new-domain.com';
function replace_canonical_with_live_url($url) {
global $liveSiteURL;
$new_url = preg_replace("/(http|https):\/\/(?:.*?)\//i", "$1://" . $liveSiteURL . "/", $url);
$url = $new_url;
return $url;
}
add_filter('wpseo_canonical', 'replace_canonical_with_live_url');
// Input: http://old-domain.com/about/
// Output: http://new-domain.com/about/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment