is_main_site() WordPress Function

This function is used to determine whether the current site is the main site in a network. If the site is the main site, this function will return true. Otherwise, it will return false.

is_main_site( int $site_id = null, int $network_id = null ) #

Determine whether a site is the main site of the current network.


Parameters

$site_id

(int)(Optional) Site ID to test. Defaults to current site.

Default value: null

$network_id

(int)(Optional) Network ID of the network to check for. Defaults to current network.

Default value: null


Top ↑

Return

(bool) True if $site_id is the main site of the network, or if not running Multisite.


Top ↑

More Information

Replaces function is_main_blog(), deprecated since 3.0.0. (wp-includes/ms-deprecated.php)


Top ↑

Source

File: wp-includes/functions.php

function is_main_site( $site_id = null, $network_id = null ) {
	if ( ! is_multisite() ) {
		return true;
	}

	if ( ! $site_id ) {
		$site_id = get_current_blog_id();
	}

	$site_id = (int) $site_id;

	return get_main_site_id( $network_id ) === $site_id;
}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0The $network_id parameter was added.
3.0.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