is_main_site( int $site_id = null, int $network_id = null )
Determine whether a site is the main site of the current network.
Description Description
Parameters Parameters
- $site_id
-
(int) (Optional) Site ID to test. Defaults to current site.
Default value: null
- $network_id
-
(int) (Optional) Network ID of the network to check for. Defaults to current network.
Default value: null
Return Return
(bool) True if $site_id is the main site of the network, or if not running Multisite.
Source Source
File: wp-includes/functions.php
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 );
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 4.9.0 | The $network_id parameter was added. |
| 3.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example
if ( is_main_site( $blog_id ) ) { // display something special for the main site. }