WordPress at a glance

is_main_site() WP 1.0

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

  • Since 4.9.0 The $network_id parameter has been added.
✈ 1 time = 0.000013s = very fast | 50000 times = 0.045192s = 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

Code of is_main_site: wp-includes/functions.php VER 4.9.8

<?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 $site_id === get_main_site_id( $network_id );
}

Related Functions

From category: Multisite

No comments
    Hello, !     Log In . Register