On this page
get_main_site_id( int $network_id = null ): int
Gets the main site ID.
Parameters
$network_idint Optional-
The ID of the network for which to get the main site.
Defaults to the current network.Default:
null
Return
int The ID of the main site.
Source
File: wp-includes/functions.php. View all references
function get_main_site_id( $network_id = null ) {
if ( ! is_multisite() ) {
return get_current_blog_id();
}
$network = get_network( $network_id );
if ( ! $network ) {
return 0;
}
return $network->site_id;
}
Related
Uses
| Uses | Description |
|---|---|
| get_network() wp-includes/ms-network.php | Retrieves network data given a network ID or network object. |
| is_multisite() wp-includes/load.php | If Multisite is enabled. |
| get_current_blog_id() wp-includes/load.php | Retrieve the current site ID. |
Used By
| Used By | Description |
|---|---|
| ms_load_current_site_and_network() wp-includes/ms-load.php | Identifies the network and site of a requested domain and path and populates the corresponding network and site global objects as part of the multisite bootstrap process. |
| is_main_site() wp-includes/functions.php | Determines whether a site is the main site of the current network. |
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_main_site_id