is_main_network() WordPress Function

The is_main_network() function in WordPress allows you to check if the current site is the main network site. This is useful for network-specific code that only needs to run on the main site.

is_main_network( int $network_id = null ) #

Determine whether a network is the main network of the Multisite installation.


Parameters

$network_id

(int)(Optional) Network ID to test. Defaults to current network.

Default value: null


Top ↑

Return

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


Top ↑

Source

File: wp-includes/functions.php

function is_main_network( $network_id = null ) {
	if ( ! is_multisite() ) {
		return true;
	}

	if ( null === $network_id ) {
		$network_id = get_current_network_id();
	}

	$network_id = (int) $network_id;

	return ( get_main_network_id() === $network_id );
}


Top ↑

Changelog

Changelog
VersionDescription
3.7.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