get_site_url()
Retrieves the URL for a given site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
Returns the site_url with the appropriate protocol, 'https' if is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() overridden.
Used By: site_url(), get_admin_url()
1 time — 0.000067 sec (very fast) | 50000 times — 2.20 sec (fast)
Hooks from the function
Return
String
. Site URL link with optional path appended.
Usage
get_site_url( $blog_id, $path, $scheme );
- $blog_id(int|null)
- Site ID.
Default: null (current site) - $path(string)
- Path relative to the site URL.
Default: '' - $scheme(string|null)
- Scheme to give the site URL context. Accepts 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
Default: null
Examples
#1 Demo
echo get_site_url(); // Displays: http://www.example.com
If WP installed into subfolder, returns:
https://www.example.com/sub/folder
#2 Let's specify the protocol forcibly
echo get_site_url( null, '/wp-content/themes/', 'https' ); // Displays: https://example.com/wp-content/themes/
#3 Get just the hostname
To get just the hostname/domain component of the Site URL (without paths, schema, etc.) you could use the following:
echo parse_url( get_site_url(), PHP_URL_HOST ); // wp-kama.com
Changelog
Since 3.0.0 | Introduced. |