Change the Primary Blog in WordPress Multisite

| | Tutorial, WordPress

In the last few years, I’ve been using WordPress Multisite with enterprise level clients. It allows me to implement websites with companion user portals and multiple language sites with a single administrative login for the managers of the sites. It also enables the a single roll-out point for WordPress and plugin updates, as well as theme adjustments as the site needs change.

Another advantage of WordPress Multisite is the ability to set up a staging site for the next version of the site in the same installation of WordPress: http://www.clientwebsite.com and http://staging.clientwebsite.com are running in the same environment with the same plugins, which means fewer surprises when it’s time for go-live, and a convenient way for the website managers to modify content with a single login.

(You’ll notice I keep fixating on the “single login” thing: this is because I’ve found that clients get confused when there are multiple URLs and username and password combinations. Which means I spend time answering questions about logins when both parties could be doing actual work. Your mileage may vary.)

The big catch to the live and staging environments in WordPress Multisite is taking the staging site live. Let’s look at how to change the primary blog in WordPress Multisite.

Change the primary blog in WordPress Multisite

Prerequisites

  • FTP access to the webserver
  • Access to the database (for example, phpMyAdmin)

1. Modify wp_config.php

Look for the following lines, which define the primary site:

define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Replace the 1 on the BLOG_ID_CURRENT_SITE line with the ID of the blog you want to make the primary site. If you need help finding the ID of the site, see My Sites > Network Admin > My Sites in your WordPress installation.

In my case, the lines become:

define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 2);

2. Modify the Database

Note: these instructions are written assuming you used the default table prefix when installing WordPress (which, of course, is not your most secure option). I am assuming that if you are comfortable editing the database, this is a minor detail to you.

a. wp_blogs

My wp_blogs table looked like this to start:

Modify the domain field so that the blog_id you want to become primary has the primary domain. Modify the domain on the previous primary domain to become a subdomain. Here is what my wp_blogs table looked like after editing:

b. wp_site

Edit the domain field to match the new subdomain you used in 2a.

c. Run a find and replace on your new primary site

Now that your former staging site is live, you need to update the content to use the primary site URL instead of the staging URL. This will fix all of your links and images in the site.

Here is the MySQL query:
UPDATE wp_posts SET post_content = REPLACE (post_content,'STAGING SITE URL','PRIMARY SITE URL');

In my example, I need to edit staging.opalgamble.com to become opalgamble.com. My MySQL query looks like this:
UPDATE wp_posts SET post_content = REPLACE (post_content,'staging.opalgamble.com','opalgamble.com');

3. Find a beverage, you’re done!

Taadaa! You managed to change the primary blog in WordPress Multisite. Time to celebrate!

Leave a Reply

 

905-901-2240