0
0
Wordpressframework~5 mins

Multisite network basics in Wordpress

Choose your learning style9 modes available
Introduction

A multisite network lets you run many WordPress sites from one installation. It saves time and makes managing sites easier.

You want to create a group of related websites, like blogs for different teams in a company.
You need to manage multiple client websites from one place.
You want to share themes and plugins across many sites without installing them repeatedly.
You want to allow users to create their own sites on your platform.
You want to keep all sites updated and secure with one WordPress core.
Syntax
Wordpress
1. Enable multisite by adding define('WP_ALLOW_MULTISITE', true); to wp-config.php
2. Go to Tools > Network Setup in WordPress admin
3. Follow instructions to add code snippets to wp-config.php and .htaccess
4. Access the Network Admin dashboard to create and manage sites

You must have access to your WordPress files to enable multisite.

Multisite can use subdomains (site1.example.com) or subdirectories (example.com/site1).

Examples
This line in wp-config.php enables the multisite feature.
Wordpress
define('WP_ALLOW_MULTISITE', true);
This code sets up multisite with subdirectory structure.
Wordpress
/* Add to wp-config.php after enabling multisite */
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
$base = '/';
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
This .htaccess code handles URL rewriting for multisite with subdirectories.
Wordpress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Sample Program

This shows the key code changes to enable and configure a multisite network in WordPress. After this, you use the WordPress admin to add and manage sites.

Wordpress
<?php
// wp-config.php snippet to enable multisite
define('WP_ALLOW_MULTISITE', true);

// After enabling multisite, add this to wp-config.php
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
$base = '/';
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

// .htaccess rules for multisite with subdirectories
/*
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
*/

// After setup, use Network Admin to add new sites
?>
OutputSuccess
Important Notes

Back up your site before enabling multisite to avoid data loss.

Some plugins may not work well with multisite.

Multisite uses more server resources than a single site.

Summary

Multisite lets you run many WordPress sites from one installation.

Enable multisite by editing wp-config.php and .htaccess files.

Manage all sites from the Network Admin dashboard.