Created
January 6, 2022 23:33
-
-
Save jordanmaslyn/7e28423ef43cdb6af068f5f192077746 to your computer and use it in GitHub Desktop.
Fix Yoast sitemaps when working with headless WP
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 | |
/* | |
* Replacing domain for rest api requests from Gutenberg editor if youre using | |
* WP headless and WP_SITEURL & WP_HOME are not the same domain | |
* (has nothing to do with yoast) | |
*/ | |
add_filter('rest_url', function($url) { | |
$url = str_replace(home_url(), site_url(), $url); | |
return $url; | |
}); | |
/* | |
* Replacing domain for stylesheet to xml if youre using WP headless | |
* and WP_SITEURL & WP_HOME are not the same domain | |
*/ | |
function filter_wpseo_stylesheet_url( $stylesheet ) { | |
$home = parse_url(home_url()); | |
$site = parse_url(site_url()); | |
return str_replace($home, $site, $stylesheet); | |
}; | |
add_filter( 'wpseo_stylesheet_url', 'filter_wpseo_stylesheet_url', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @jordanmaslyn Thank you for your response, Basically, i changed "Site Address (URL)" from wp-admin/options-general.php then everything looks good but when I try to log in from any other browser or try to logout from right top corner it redirects me to the Frontend url with the required parameters.