Title: get_main_network_id
Published: August 18, 2015
Last modified: May 20, 2026

---

# get_main_network_id(): int

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#wp--skip-link--target)

Gets the main network ID.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#return)󠁿

 int The ID of the main network.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#source)󠁿

    ```php
    function get_main_network_id() {
    	if ( ! is_multisite() ) {
    		return 1;
    	}

    	$current_network = get_network();

    	if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
    		$main_network_id = PRIMARY_NETWORK_ID;
    	} elseif ( isset( $current_network->id ) && 1 === (int) $current_network->id ) {
    		// If the current network has an ID of 1, assume it is the main network.
    		$main_network_id = 1;
    	} else {
    		$_networks       = get_networks(
    			array(
    				'fields' => 'ids',
    				'number' => 1,
    			)
    		);
    		$main_network_id = array_shift( $_networks );
    	}

    	/**
    	 * Filters the main network ID.
    	 *
    	 * @since 4.3.0
    	 *
    	 * @param int $main_network_id The ID of the main network.
    	 */
    	return (int) apply_filters( 'get_main_network_id', $main_network_id );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/functions.php#L6514)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/functions.php#L6514-L6544)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#hooks)󠁿

 [apply_filters( ‘get_main_network_id’, int $main_network_id )](https://developer.wordpress.org/reference/hooks/get_main_network_id/)

Filters the main network ID.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#related)󠁿

| Uses | Description | 
| [get_network()](https://developer.wordpress.org/reference/functions/get_network/)`wp-includes/ms-network.php` |

Retrieves network data given a network ID or network object.

  | 
| [get_networks()](https://developer.wordpress.org/reference/functions/get_networks/)`wp-includes/ms-network.php` |

Retrieves a list of networks.

  | 
| [is_multisite()](https://developer.wordpress.org/reference/functions/is_multisite/)`wp-includes/load.php` |

Determines whether Multisite is enabled.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#)

| Used by | Description | 
| [WP_Application_Passwords::is_in_use()](https://developer.wordpress.org/reference/classes/wp_application_passwords/is_in_use/)`wp-includes/class-wp-application-passwords.php` |

Checks if application passwords are being used by the site.

  | 
| [WP_Application_Passwords::create_new_application_password()](https://developer.wordpress.org/reference/classes/wp_application_passwords/create_new_application_password/)`wp-includes/class-wp-application-passwords.php` |

Creates a new application password.

  | 
| [is_site_meta_supported()](https://developer.wordpress.org/reference/functions/is_site_meta_supported/)`wp-includes/functions.php` |

Determines whether site meta is enabled.

  | 
| [get_current_network_id()](https://developer.wordpress.org/reference/functions/get_current_network_id/)`wp-includes/load.php` |

Retrieves the current network ID.

  | 
| [upgrade_network()](https://developer.wordpress.org/reference/functions/upgrade_network/)`wp-admin/includes/upgrade.php` |

Executes network-level upgrade routines.

  | 
| [is_main_network()](https://developer.wordpress.org/reference/functions/is_main_network/)`wp-includes/functions.php` |

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

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_main_network_id/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_main_network_id%2F)
before being able to contribute a note or feedback.