WordPress Multisite is the default feature of the WordPress that lets you create the collection of the independent websites sharing the same WordPress installation. These websites don’t have their own directory on the server and act as virtual websites. But, all these websites do have their separate directories for the media uploads and separate tables in the database. WordPress by default provides you the functionality to create the Multisite from the admin dashboard.
You can easily create the new WordPress Multisite from the WordPress admin panel. You need to set up a few things only and your multisite WordPress website will be ready to use. Check out the screenshot how you can create multisite from the WordPress Admin.
User thinks that it takes hours to set up the multisite network for the WordPress website. But the fact is that it takes only a few minutes to set up the network. Admin can easily create that from the backend. But what if you don’t wish to involve the admin every time when you wish to create the version of the multisite?
You can create the multisite without involving the admin every time.
Yes, it is possible and very easy to set up. What you need to do is just a little bit of custom coding and you will be all set to setup you dynamic multisite WordPress set up. People think that it’s a time taking the task to create a new site. Here, I am giving you the formula to set up the multisite WordPress website in less than 60 minutes.
There is a function in the WordPress that will create a new blog in multisite: wpmu_create_blog
This function has 4 parameters.
- It is the domain of the new blog
- The path of the new blog
- The title of the new blog
- The user id of the user account who will be the blog admin
The function will return the site id on success and WP_error object on failure.
$site_id = wpmu_create_blog ( ‘krishaweb.com’, ‘/newsite’, ‘Title of New site’, ‘1’ );
Now, if you wish to activate any theme for the newly created site, you first need to switch to the site using the switch_to_blog function. This function will allow you to get the details of any blog. You just need to pass the site id to it as the parameter.
switch_to_blog( $site_id );
Now you can use the switch_theme function that will allow the provided theme to activate for the current site.
switch_theme( ‘theme_name’ );
And that’s it. The website is ready with the theme you have activated for it. You can do amendments in it from the admin panel.
Just the one last step to restore the current blog as we have used switch_to_blog function. For that the function is restore_current_blog.
So, this is how you can set up dynamic Multisite WordPress Website using the code in less than 60 minutes. I hope this will help you with your next WordPress Multisite set up. Write down your queries in a comment below or Feel free to Contact Us. We would love to help you with your WordPress needs.