is_main_site

The timeline below displays how wordpress function is_main_site has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Determines whether a site is the main site of the current network.
 *
 * @since 3.0.0
 * @since 4.9.0 The `$network_id` parameter was added.
 *
 * @param int $site_id    Optional. Site ID to test. Defaults to current site.
 * @param int $network_id Optional. Network ID of the network to check for.
 *                        Defaults to current network.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
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;
}

WordPress Version: 5.4

/**
 * Determine whether a site is the main site of the current network.
 *
 * @since 3.0.0
 * @since 4.9.0 The `$network_id` parameter was added.
 *
 * @param int $site_id    Optional. Site ID to test. Defaults to current site.
 * @param int $network_id Optional. Network ID of the network to check for.
 *                        Defaults to current network.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
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;
}

WordPress Version: 5.1

/**
 * Determine whether a site is the main site of the current network.
 *
 * @since 3.0.0
 * @since 4.9.0 The `$network_id` parameter was added.
 *
 * @param int $site_id    Optional. Site ID to test. Defaults to current site.
 * @param int $network_id Optional. Network ID of the network to check for.
 *                        Defaults to current network.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
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);
}

WordPress Version: 4.9

/**
 * Determine whether a site is the main site of the current network.
 *
 * @since 3.0.0
 * @since 4.9.0 The $network_id parameter has been added.
 *
 * @param int $site_id    Optional. Site ID to test. Defaults to current site.
 * @param int $network_id Optional. Network ID of the network to check for.
 *                        Defaults to current network.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
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);
}

WordPress Version: 4.7

/**
 * Determine whether a site is the main site of the current network.
 *
 * @since 3.0.0
 *
 * @param int $site_id Optional. Site ID to test. Defaults to current site.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
function is_main_site($site_id = null)
{
    if (!is_multisite()) {
        return true;
    }
    if (!$site_id) {
        $site_id = get_current_blog_id();
    }
    return (int) $site_id === (int) get_network()->site_id;
}

WordPress Version: 4.6

/**
 * Determine whether a site is the main site of the current network.
 *
 * @since 3.0.0
 *
 * @global object $current_site
 *
 * @param int $site_id Optional. Site ID to test. Defaults to current site.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
function is_main_site($site_id = null)
{
    // This is the current network's information; 'site' is old terminology.
    global $current_site;
    if (!is_multisite()) {
        return true;
    }
    if (!$site_id) {
        $site_id = get_current_blog_id();
    }
    return (int) $site_id === (int) $current_site->blog_id;
}

WordPress Version: 4.3

/**
 * Determine whether a site is the main site of the current network.
 *
 * @since 3.0.0
 *
 * @global object $current_site
 *
 * @param int $site_id Optional. Site ID to test. Defaults to current site.
 *                     Defaults to current site.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
function is_main_site($site_id = null)
{
    // This is the current network's information; 'site' is old terminology.
    global $current_site;
    if (!is_multisite()) {
        return true;
    }
    if (!$site_id) {
        $site_id = get_current_blog_id();
    }
    return (int) $site_id === (int) $current_site->blog_id;
}

WordPress Version: 4.0

/**
 * Determine whether a site is the main site of the current network.
 *
 * @since 3.0.0
 *
 * @param int $site_id Optional. Site ID to test. Defaults to current site.
 *                     Defaults to current site.
 * @return bool True if $site_id is the main site of the network, or if not
 *              running Multisite.
 */
function is_main_site($site_id = null)
{
    // This is the current network's information; 'site' is old terminology.
    global $current_site;
    if (!is_multisite()) {
        return true;
    }
    if (!$site_id) {
        $site_id = get_current_blog_id();
    }
    return (int) $site_id === (int) $current_site->blog_id;
}

WordPress Version: 3.7

/**
 * Whether a site is the main site of the current network.
 *
 * @since 3.0.0
 *
 * @param int $site_id Optional. Site ID to test. Defaults to current site.
 * @return bool True if $site_id is the main site of the network, or if not running multisite.
 */
function is_main_site($site_id = null)
{
    // This is the current network's information; 'site' is old terminology.
    global $current_site;
    if (!is_multisite()) {
        return true;
    }
    if (!$site_id) {
        $site_id = get_current_blog_id();
    }
    return (int) $site_id === (int) $current_site->blog_id;
}