get_main_site_id()WP 4.9.0

Gets the main site ID.

No Hooks.

Return

Int. The ID of the main site.

Usage

get_main_site_id( $network_id );
$network_id(int)
The ID of the network for which to get the main site.
Default: 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.4.3

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;
}