get_main_site_id()WP 4.9.0

Gets the ID of the main site of the network.

No Hooks.

Returns

Int. site ID.

Usage

get_main_site_id( $network_id );
$network_id(integer)
The ID of the network, the ID of the main site of which needs to be obtained. Usually, only one network is used in multisite mode...
Default: null (current network)

Examples

0

#1 Get the ID of the main network site.

$main_site_id = get_main_site_id();

Changelog

Since 4.9.0 Introduced.

get_main_site_id() code WP 6.9

function get_main_site_id( $network_id = null ) {
	if ( ! is_multisite() ) {
		return get_current_blog_id();
	}

	$network = get_network( $network_id );
	if ( ! $network ) {
		return 0;
	}

	return $network->site_id;
}