rest_url()WP 4.4.0

Retrieves the URL to a REST endpoint.

Note: The returned URL is NOT escaped.

1 time — 0.0041261 sec (very slow) | 50000 times — 8.83 sec (fast)

No Hooks.

Return

String. Full URL to the endpoint.

Usage

rest_url( $path, $scheme );
$path(string)
REST route.
Default: ''
$scheme(string)
Sanitization scheme.
Default: 'rest'

Examples

0

#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() code WP 6.4.3

function rest_url( $path = '', $scheme = 'rest' ) {
	return get_rest_url( null, $path, $scheme );
}