Using WordPress ‘install_network()’ PHP function

The install_network() WordPress PHP function installs a new network for a WordPress multisite installation.

Usage

To use the install_network() function, simply call it without any parameters:

install_network();

Parameters

There are no parameters for this function.

More information

See WordPress Developer Resources: install_network()

This function was introduced in WordPress version 3.0.0. There are no deprecations or related functions.

Examples

Installing a new network

The following example demonstrates how to install a new network using the install_network() function:

// Call the install_network function to install a new network
install_network();

Conditionally installing a new network

This example checks if a network is already installed, and if not, installs a new network using the install_network() function:

// Check if the network is installed
if (!is_multisite()) {
    // If not, install a new network
    install_network();
}

Installing a network and redirecting

In this example, the install_network() function is used to install a new network, and then the user is redirected to a custom page:

// Install a new network
install_network();

// Redirect the user to a custom page after network installation
wp_redirect('https://example.com/custom-page');
exit;

Adding an action after installing a network

This example demonstrates how to run a custom function after installing a new network with the install_network() function:

// Install a new network
install_network();

// Custom function to run after installing the network
function after_network_install() {
    // Perform any custom actions here
}

// Add the custom function to the 'after_setup_theme' action
add_action('after_setup_theme', 'after_network_install');

Installing a network and updating the site option

In this example, the install_network() function is used to install a new network, and then a site option is updated:

// Install a new network
install_network();

// Update the site option 'my_custom_option' with the value 'Hello, Network!'
update_site_option('my_custom_option', 'Hello, Network!');