rest_url()
Gets the REST API URL for the current site. You can specify a specific route.
Differs from get_rest_url() in that there is no option to specify the site ID of the network here, while there is there.
The returned URL is not sanitized for output. Therefore, use the function esc_url() before outputting.
1 time — 0.0041261 sec (very slow) | 50000 times — 8.83 sec (fast)
No Hooks.
Returns
String. URL to the REST API endpoint.
Usage
rest_url( $path, $scheme );
- $path(string)
- REST route (path). Added to the end of the URL, the last slash is removed if it exists.
Default: '' - $scheme(string)
- Data cleaning scheme. Passed to get_home_url().
Default: 'rest'
Examples
#1 Demo
Get the URLs of the different REST endpoints.
echo rest_url(); //> http://example.com/wp-json/ echo rest_url( '/foo' ); //> http://example.com/wp-json/foo echo rest_url( '/foo', 'https' ); //> https://example.com/wp-json/foo
Changelog
| Since 4.4.0 | Introduced. |
rest_url() rest url code WP 6.8.3
function rest_url( $path = '', $scheme = 'rest' ) {
return get_rest_url( null, $path, $scheme );
}