Last active
October 15, 2021 16:21
-
-
Save itsHall/32d1f4493104705969207ff77c67049f to your computer and use it in GitHub Desktop.
Replace Domain Name In Yoast SEO Canonical URL (Flywheel Local Bug Fix)
This file contains 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 | |
//------------------------------------------------// | |
// 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