network_site_url()
Retrieves the site URL for the current network.
Returns the site URL with the appropriate protocol, 'https' if is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is overridden.
Hooks from the function
Returns
String. Site URL link with optional path appended.
Usage
network_site_url( $path, $scheme );
- $path(string)
- Path relative to the site URL.
Default:'' - $scheme(string|null)
- Scheme to give the site URL context. Accepts
'http','https', or'relative'.
Default:null
Notes
- See: set_url_scheme()
Changelog
| Since 3.0.0 | Introduced. |
network_site_url() network site url code WP 6.9.1
function network_site_url( $path = '', $scheme = null ) {
if ( ! is_multisite() ) {
return site_url( $path, $scheme );
}
$current_network = get_network();
if ( 'relative' === $scheme ) {
$url = $current_network->path;
} else {
$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
}
if ( $path && is_string( $path ) ) {
$url .= ltrim( $path, '/' );
}
/**
* Filters the network site URL.
*
* @since 3.0.0
*
* @param string $url The complete network site URL including scheme and path.
* @param string $path Path relative to the network site URL. Blank string if
* no path is specified.
* @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https',
* 'relative' or null.
*/
return apply_filters( 'network_site_url', $url, $path, $scheme );
}