Using WordPress ‘is_subdomain_install()’ PHP function

The is_subdomain_install() WordPress PHP function checks if a subdomain configuration is enabled in a WordPress multisite setup.

Usage

To use the function, simply call it and check the returned value:

$is_subdomain = is_subdomain_install();

Parameters

This function has no parameters.

More information

See WordPress Developer Resources: is_subdomain_install()

This function is available in WordPress since version 3.0.0.

Examples

Check if subdomain install and display message

Check if the site uses a subdomain configuration and display a message accordingly.

$is_subdomain = is_subdomain_install();

if ($is_subdomain) {
    echo "This is a subdomain installation.";
} else {
    echo "This is not a subdomain installation.";
}

Change the behavior based on subdomain install

Perform different actions based on whether the site is using a subdomain configuration.

$is_subdomain = is_subdomain_install();

if ($is_subdomain) {
    // Perform subdomain specific action
} else {
    // Perform non-subdomain specific action
}

Show different content for subdomain and non-subdomain installs

Display different content on the site based on the type of installation.

$is_subdomain = is_subdomain_install();

if ($is_subdomain) {
    echo "Content for subdomain installations";
} else {
    echo "Content for non-subdomain installations";
}

Redirect user based on subdomain installation

Redirect users to different pages depending on whether the site is using a subdomain configuration.

$is_subdomain = is_subdomain_install();

if ($is_subdomain) {
    wp_redirect("https://subdomain.example.com");
    exit;
} else {
    wp_redirect("https://example.com");
    exit;
}

Enqueue different styles or scripts for subdomain installations

Load different styles or scripts based on the type of installation.

$is_subdomain = is_subdomain_install();

if ($is_subdomain) {
    wp_enqueue_style("subdomain-style", "path/to/subdomain-style.css");
} else {
    wp_enqueue_style("non-subdomain-style", "path/to/non-subdomain-style.css");
}