Previously I’d only ever posted this in my ebook, WordPress Multisite 110.

What people mean by this is the site they originally set to be seen at domain.com is no longer the one they want to use, but the one at (say) domain.com/temp or temp.domain.com. If this is what you’re wanting to due, it’s not impossible, but it is annoying and a little tricky. If you’re using the trick to give WP it’s own directory, these are not the directions you’re looking for. I haven’t written those out yet.

First you have to go to Network Dashboard > Sites and edit the site you want to be the main site.

Example.com using two

This you want to to look like this:

Changing the subset two to no folder name

Make certain you leave ‘Update siteurl and home as well’ checked! If you forget that, you’ll be sad. You no longer need to check the box (it’s gone in newer versions of WP), but if you DO have it, check it.

Now you’d think you go to edit the main site and change it, but you can’t.

Default main site is not editable

By default, the main site is not editable. This makes sense when you think about how messy this might be, so in order to edit it you have to go to your wp-config.php file and look for this line:

define('BLOG_ID_CURRENT_SITE', 1);

Change it to the site ID you want to use as your main site. In this example, I want site #2, aka, two, to become my main site.

define('BLOG_ID_CURRENT_SITE', 2);

Save the file and then you have to go back to your Sites and edit the old main site.

Main site can now be edited

Give its path a new name and press save, making sure you keep that checkbox checked if it’s there.

Change the original main site to new

In this example, I’ve picked a new URL for my formerly main site becuase I don’t want any conflicts, but there’s nothing stopping me from picking ‘two’ again and just totally swapping things.

The last step is to change your post content. Using a plugin like Velvet Blues Update URLs, you will need to search each site separately and replace the URLs. If you have wp-cli, you can do that too like this:

wp search-replace 'example.com' 'example.com/new' wp_posts wp_postmeta --dry-run
wp search-replace 'example.com/two' 'example.com' wp_2_posts wp_2_postmeta --dry-run

If those look good, rerun without dry run and call it a day!

An interesting quirk is that you may need to edit the Fileupload URL if you’re using blogs.dir for your images. I noticed that on one site it was set to http://example/two/files which clearly is wrong. To fix that, go to Network Admin, click on Sites, and click on edit for the site. From there, click on the dangerous “Settings” tab and look for “Fileupload URL” and edit as needed to match things.

Cool tricks like this can be found in WordPress Multisite 110.

Reader Interactions

Comments

  1. Thanks for the post Mika Epstein.
    Whenever I struggle with MultiSite issues, I recall your warning/caution against using it.

    I wanted to be clear on the implication of this trick.
    While the homepage example.com/two/ becomes example.com/;
    what happens to example.com/two/post-permalink/?

    Will it be example.com/blog/post-permalink/ or example.com/post-permalink/ ?

    Thanks in advance.

    • @daniel:

      While the homepage example.com/two/ becomes example.com/;
      what happens to example.com/two/post-permalink/?

      It becomes example.com/blog/post-permalink/

      The blog slug is applied based on detection of the main site (BLOG_ID_CURRENT_SITE) so that will apply itself again.

  2. Thanks.
    One more thing:
    Was the search-replace instruction was supposed to be like this?

    wp search-replace ‘example.com’ ‘example.com/new’ wp_posts wp_postmeta –dry-run
    wp search-replace ‘example.com/two‘ ‘example.com’ wp_2_posts wp_2_postmeta –dry-run

    The instruction is the same on the book – but it seemed to me a typo.
    [If my comment doesn’t make sense, just remove it. I might have missed something]

  3. Hi

    I have tried to follow your instructions but something went wrong as I was not allowed to change the main site to a new path.

    In my wp-config.php I have

    /* Multisite */
    define( ‘WP_ALLOW_MULTISITE’, true );
    define(‘MULTISITE’, true);
    define(‘SUBDOMAIN_INSTALL’, false);
    define(‘DOMAIN_CURRENT_SITE’, ‘mydomain.xy’);
    define(‘PATH_CURRENT_SITE’, ‘/’);
    define(‘SITE_ID_CURRENT_SITE’, 1);
    define(‘BLOG_ID_CURRENT_SITE’, 1);

    Should I change somerwhere else besides define(‘BLOG_ID_CURRENT_SITE’, 1);

    tia.

    • @René: Assuming you properly changed BLOG_ID_CURRENT_SITE AWAY from 1 (you have to change that the site number for your new main site), no that’s all. But if you came here from the forum post I linked to yesterday, post THERE, not here 🙂

%d bloggers like this: