get_main_site_id() WordPress Function

The get_main_site_id() function is used to get the id of the main site in a WordPress network.

get_main_site_id( int $network_id = null ) #

Gets the main site ID.


Parameters

$network_id

(int)(Optional) The ID of the network for which to get the main site. Defaults to the current network.

Default value: null


Top ↑

Return

(int) The ID of the main site.


Top ↑

Source

File: wp-includes/functions.php

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


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More