is_main_site

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

Description

is_main_site( (null) $site_id = null ); 

Parameters (1)

0. $site_id — Optional. (null) => null
Site ID to test. Defaults to current site.

Usage

  1. if ( !function_exists( 'is_main_site' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Optional. Site ID to test. Defaults to current site. 
  5. $site_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = is_main_site($site_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function is_main_site( $site_id = null ) { 
  2. if ( ! is_multisite() ) 
  3. return true; 
  4.  
  5. if ( ! $site_id ) 
  6. $site_id = get_current_blog_id(); 
  7.  
  8. return (int) $site_id === (int) get_network()->site_id;