If you change the site URL option to use a different one from your
installed directory, the /wp-json/
is base changes too.
This plugin fixes that.
- Download a ZIP of this plugin
- Upload to WordPress
<?php | |
/** | |
* Plugin Name: Fix REST URL on Site URL | |
* Plugin URI: https://gist.github.com/lightningspirit/61c8810778a3a88192b3ca5060dc3efb | |
* Description: Fix WordPress REST base to use real URL | |
* Author: Move Your Digital, Inc. | |
* Author URI: https://moveyourdigital.com | |
* Version: 0.1.0 | |
* | |
* @package Fix_Rest_Url_Site_Url | |
*/ | |
/* | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
add_filter('home_url', function ($url, $path, $origin_scheme, $blog_id) { | |
if ($origin_scheme == "rest") { | |
return get_site_url($blog_id, $path); | |
} elseif ($path && strpos('wp-json', $path) !== false) { | |
return get_site_url($blog_id, $path); | |
} else { | |
return $url; | |
} | |
}, 10, 4); |