The is_main_network() WordPress PHP function determines whether a network is the main network of the Multisite installation.
Usage
is_main_network( $network_id );
Example:
Input:
is_main_network( 2 );
Output: false
Parameters
$network_id (int)(optional) – Network ID to test. Defaults to the current network. Default:null.
More information
See WordPress Developer Resources: is_main_network
Examples
Check if the current network is the main network
if ( is_main_network() ) {
echo 'This is the main network.';
} else {
echo 'This is not the main network.';
}
Check if a specific network is the main network
$network_id = 3;
if ( is_main_network( $network_id ) ) {
echo 'Network ' . $network_id . ' is the main network.';
} else {
echo 'Network ' . $network_id . ' is not the main network.';
}
Display network-specific content
if ( is_main_network() ) {
echo 'Welcome to the main network!';
} else {
echo 'Welcome to our sub-network!';
}
Conditional menu display
if ( is_main_network() ) {
wp_nav_menu( array( 'theme_location' => 'main-network-menu' ) );
} else {
wp_nav_menu( array( 'theme_location' => 'sub-network-menu' ) );
}
Customizing page titles
function custom_page_title( $title ) {
if ( is_main_network() ) {
$title .= ' - Main Network';
} else {
$title .= ' - Sub Network';
}
return $title;
}
add_filter( 'wp_title', 'custom_page_title', 10, 2 );