WordPress is_main_site() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress Multisite, is_main_site() returns true when a site is the main (first) site of the network. Sub-sites return false.

On a normal single-site install it always returns true. Use it when some feature should run only on the main site of a network.

Syntax

Use it as the test of an if statement.

WordPress
if ( is_main_site() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_main_site()True if the current site is the main site.
is_main_site( 3 )True if the site with ID 3 is the main site.
is_multisite()Check first if the install is a network.

Related: get_current_blog_id() returns the ID of the current site.

Full declaration
WordPress
is_main_site( int|null $site_id = null, int|null $network_id = null ): bool

Parameters

ParameterDescription
$site_idOptional. The ID of the site to check. Default is null, which means the current site.
$network_idOptional. The network ID. Default is null, which means the current network.

Return Value

Return ValueDescription
booltrue if the site is the main site, otherwise false.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Show a note on the main site

Print a message only on the main site.

WordPress
<?php if ( is_main_site() ) {
  echo 'Welcome to the main site.';
} else {
  echo 'Welcome to a sub-site.';
} ?>

How It Works

  1. is_main_site() checks the current site.
  2. The if branch runs on the main site.
  3. Sub-sites use the else branch.

Example 2 — Network only

Combine with is_multisite().

WordPress
<?php if ( is_multisite() && is_main_site() ) {
  echo 'You are on the main site of a network.';
} ?>

How It Works

  1. is_multisite() is true only on a network.
  2. is_main_site() narrows it to the first site.
  3. On a single-site install the first part fails, so nothing is printed.

Example 3 — Check a site by ID

Pass a site ID to test it.

WordPress
<?php if ( is_main_site( 1 ) ) {
  echo 'Site 1 is the main site.';
} ?>

How It Works

  1. The argument 1 is a site ID.
  2. The tag checks that site, not the current one.
  3. Most networks use ID 1 for the main site.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
It returns true, because a single site is its own main site.
Use get_current_blog_id().
No. is_main_site() is about a site. is_super_admin() is about a user.

Next: is_month()

Check if the current page is a monthly archive.

is_month() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful