The network_home_url() WordPress PHP function retrieves the home URL for the current network.
Usage
network_home_url( $path = '', $scheme = null );
Parameters
$path
(string, Optional): Path relative to the home URL. Default:''
$scheme
(string|null, Optional): Scheme to give the home URL context. Accepts ‘http’, ‘https’, or ‘relative’. Default:null
More information
See WordPress Developer Resources: network_home_url
Examples
Get the network home URL
This example retrieves the network home URL.
$url = network_home_url(); echo $url; // Output: http://www.example.com (trailing slash may be present)
Get the network home URL with a specific path
This example retrieves the network home URL with a custom path.
$url = network_home_url( 'blog' ); echo $url; // Output: http://www.example.com/blog
Get the network home URL with HTTPS
This example retrieves the network home URL with the HTTPS scheme.
$url = network_home_url( '', 'https' ); echo $url; // Output: https://www.example.com
Get the network home URL with a specific path and HTTPS
This example retrieves the network home URL with a custom path and the HTTPS scheme.
$url = network_home_url( 'blog', 'https' ); echo $url; // Output: https://www.example.com/blog
Get the network home URL as a relative URL
This example retrieves the network home URL as a relative URL.
$url = network_home_url( '', 'relative' ); echo $url; // Output: / (or /subdirectory if in a subdirectory)