Use network_home_url( $path="", $scheme = null )
.
You can see it in /wp-includes/link-template.php
.
Examples:
// Root of main site
$network_home = network_home_url();
// About page on main site
$network_about = network_home_url( 'about/' );
In a network, the main site has always the same ID as the network ID. network_home_url()
uses get_current_site()
which return the global variable (sigh) $current_site
, an instance of stdClass
. This one is filled in wp-includes/ms-settings.php
, which in turn is loaded in wp-settings.php
before mu-plugins are loaded.
So you can rely on it in your plugin or theme.