The network_site_url() WordPress PHP function retrieves the site URL for the current network.
Usage
network_site_url( string $path = '', string|null $scheme = null )
Custom example:
Input: network_site_url( '/about-us/', 'https' )
Output: 'https://www.example.com/about-us/'
Parameters
$path
(string) Optional: Path relative to the site URL. Default:''
$scheme
(string|null) Optional: Scheme to give the site URL context. Accepts'http'
,'https'
, or'relative'
. Default:null
More information
See WordPress Developer Resources: network_site_url()
Examples
Get the current network site URL
Retrieve the current site URL with the appropriate protocol (HTTP or HTTPS).
$url = network_site_url(); echo $url;
Get a specific page URL within the current network site
Retrieve the URL for the ‘contact-us’ page on the current network site.
$url = network_site_url('/contact-us/'); echo $url;
Get a secure URL for a specific page within the current network site
Retrieve the secure URL (HTTPS) for the ‘about-us’ page on the current network site.
$url = network_site_url('/about-us/', 'https'); echo $url;
Get the URL for the current network site using a specific scheme
Force the use of HTTP for the current network site URL.
$url = network_site_url('', 'http'); echo $url;
Get the URL for a specific page within the current network site using a relative scheme
Retrieve the URL for the ‘services’ page on the current network site using a relative scheme.
$url = network_site_url('/services/', 'relative'); echo $url;