To create a subdomain in WordPress, you will need to set up the subdomain in your DNS manager. In this tutorial, I will use the Namecheap procedure, which is very similar to other platforms. The rest of the tutorial is described in WordPress using the MultiSite feature.
All steps described in this article include screenshots to make it easy for all WordPress users to follow them easily.
NOTE: If you have already created your subdomain on your server, start reading from here to set up the subdomain in WordPress.
How to Create a Subdomain in WordPress: Creating and Pointing the Subdomain in Your Hosting
As said in the previous introduction, the first section of this tutorial shows how to create and configure a subdomain to be used by WordPress. Although this section is based on the Namecheap hosting provider, the same is applied for GoDaddy, HostGator, and other providers.
If you already know how to create and redirect a subdomain to your server IP address, start reading the next section of this article to continue the necessary steps to enable the subdomain in your WordPress.
To begin creating your subdomain on your server, log in to your hosting account and go to the DNS section of your domain name. In the following example, you can see how it seems on Namecheap:
Once in the DNS configuration panel, add a new A record.
Define your subdomain and point it to your server IP address.
In the following example, I add the en.domain.com to create a new site for native English visitors (Only type the first part of the subdomain without including the whole domain or main domain) with the server IP address as a value. Then, press the checkmark icon, or Add/Accept button depending on your hosting.
By following the previous steps, you created and redirected the subdomain to the server IP address. Now, keep reading below to add the subdomain in your cPanel/Plesk.
Creating a Subdomain in cPanel:
After creating the subdomain(s) in your hosting, you need to add it to cPanel, Plesk, or the hosting manager.
If you are using cPanel, find the Subdomains option on the main screen, as shown below:
In the Subdomain field, type the first part of the subdomain without including dots or the main domain. In my case, I only type “en” because I want to create a subdomain for the English language.
In the Domain field, only type the main domain name (e.g. domain.com).
Then, press the Create button.
If you see the Success message, your subdomain has been added to cPanel.
How to Create a Subdomain(s) in WordPress Using MultiSite:
Before enabling the MultiSite feature to add a subdomain in WordPress, let’s prepare your installation.
To begin, let’s disable all your plugins. On your dashboard’s left panel, move your mouse cursor over Appearance and then press the Installed Plugins option, as shown in the following image:
To disable all plugins, in the Bulk Actions dropdown menu (Black arrow) select Deactivate. Then, checkmark Plugin (Red Arrow) and press the Apply button (Blue arrow):
Let’s define friendly URLs or permalinks by moving your mouse cursor over Settings in your dashboard’s left menu. Then, press the Permalinks option, as shown below:
Once in the permalinks configuration screen, define friendly permalinks. In my case, I choose “Post name”. After selecting your desired permalinks type, press the Save button.
Now, go back to the cPanel’s main screen and select the File Manager option.
Once in the File Manager, move to your website root domain and find the file named wp-config.php. Next, right-click it and press the Edit option.
When the confirmation is requested, press the Edit button to continue.
Find the line “/* Add any custom values between this line and the “stop editing line. */” and exactly above it, add the following line. Then, press the Save Changes button.
NOTE: After saving the changes, don’t close the File Manager.
Go back to the WordPress dashboard and refresh the page.
Move your mouse cursor over Tools and press the Network Setup option.
In the following screen, select the Sub-domains option, type your site title and administrator email. Then, press the Install button:
The next screen will show two pieces of code. The first code (Black arrow) must be added to your wp-config.php file. Copy it and follow the steps below:
Copy the upper code in the wp-config.php file, just above the line “/* Add any custom values between this line and the “stop editing line. */”.
Then, press the Save Changes button.
Now, go back to the WordPress dashboard and copy the lower code.
Once copied, go back to the File Manager and press the Settings button in the upper-right corner.
Make sure Show Hidden Files(dofiles) is selected and press the Save button.
In the File Manager, find the .htaccess file, right-click it and press the Edit button.
Paste the code between the lines #Begin WordPress and #END WordPress.
Go back to the dashboard and press the Log in link, as shown below. Then, log in again to your dashboard.
Once Logged in, move your cursor over My Sites in the upper-left corner, then over My Blog and press Sites.
In the displayed screen, you will see your main site. Press the Add New button to add a subdomain.
In the Add New Site screen, add your subdomain (in my case “en”), the site title, language, and administrator email address. Then, press the Add Site button.
After adding your site, the screen will remain in the Add New Site panel. Move your mouse cursor over Sites in the left menu.
Now, your subdomain is listed among your sites. Move your mouse cursor over the site you want to manage and press Dashboard to manage it.
That’s how to add subdomains in WordPress, and you can add as many subdomains as you want.
Enabling multisite must be done on a fresh WordPress installation free of customization except for the instructions in this article (Disabling plugins and setting friendly permalinks). If you already have a site to which you want to add the multisite feature, you can export a backup, create a fresh installation, and restore your WordPress backup.
This article discussed the creation of subdomains is not a short process, but it’s easy. All WordPress users can achieve this task by following the steps provided. Once you enable the multisite feature, you can add as many subdomains as needed. Thank you for reading this WordPress tutorial explaining how to create subdomains in WordPress. Keep following Linux Hint for more WordPress professional tutorials.