WordPress at Your Fingertips

is_main_site() WP 1.0

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

1 time — 0.000013 sec (very fast) | 50000 times — 0.045192 sec (speed of light)

No Hooks.

Return

true|false. True if $site_id is the main site of the network, or if not running Multisite.

Usage

is_main_site( $site_id, $network_id );
$site_id(int)
Site ID to test.
Default: current site
$network_id(int)
Network ID of the network to check for.
Default: current network

Changelog

Since 3.0.0 Introduced.
Since 4.9.0 The $network_id parameter was added.

Code of is_main_site() WP 5.8.1

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

Multisite

No comments
    Log In