Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active December 28, 2020 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/d60ab5ba42a4323bdde06228124a4f62 to your computer and use it in GitHub Desktop.
Save wpscholar/d60ab5ba42a4323bdde06228124a4f62 to your computer and use it in GitHub Desktop.
A WordPress plugin that updates the REST URL to use the site URL instead of the home URL.
<?php
/**
* Custom Rest URL
*
* @package CustomRestUrl
* @author Micah Wood
* @copyright Copyright 2021 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
* @wordpress-plugin
* Plugin Name: Custom Rest URL
* Plugin URI: https://gist.github.com/wpscholar/d60ab5ba42a4323bdde06228124a4f62
* Description: A WordPress plugin that updates the REST URL to use the site URL instead of the home URL.
* Version: 1.0
* Requires PHP: 5.6
* Requires at least: 5.0
* Author: Micah Wood
* Author URI: https://wpscholar.com
* License: GPL V2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
add_filter(
'rest_url',
function ( $url, $path, $blog_id, $scheme ) {
return get_site_url( $blog_id, trailingslashit( rest_get_url_prefix() ) . $path, $scheme );
},
10,
4
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment