set_url_scheme()
Sets the scheme for a URL.
Uses: is_ssl(), force_ssl_admin()
Used By: get_home_url()
1 time — 0.000017 sec (very fast) | 50000 times — 0.07 sec (speed of light) | PHP 7.0.2, WP 4.4.1
Hooks from the function
Return
String
. URL with chosen scheme.
Usage
set_url_scheme( $url, $scheme );
- $url(string) (required)
- Absolute URL that includes a scheme
- $scheme(string|null)
- Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
Default: null
Examples
#1 Demo of protocol changes in the URL.
The code was executed on a site with HTTPS protocol by default:
$res = [ set_url_scheme( 'http://example.com/foo' ), //> https://example.com/foo OR http://example.com/foo set_url_scheme( 'http://example.com/foo', 'http' ), //> http://example.com/foo set_url_scheme( 'http://example.com/foo', 'https' ), //> https://example.com/foo set_url_scheme( 'http://example.com/foo', 'relative' ), //> /foo set_url_scheme( '//example.com/foo' ), //> https://example.com/foo OR http://example.com/foo set_url_scheme( '//example.com/foo', 'http' ), //> http://example.com/foo set_url_scheme( '//example.com/foo', 'https' ), //> https://example.com/foo set_url_scheme( '//example.com/foo', 'relative' ), //> /foo // Doesn't work with non-URL strings (return it as is) set_url_scheme( '/foo', 'https' ), //> /foo set_url_scheme( 'example.com/foo', 'https' ), //> example.com/foo // non-standard set_url_scheme( '///example.org/foo', 'https' ), //> https:///example.org/foo ]; print_r( $res );
Changelog
Since 3.4.0 | Introduced. |
Since 4.4.0 | The 'rest' scheme was added. |