Changing the Domain on a WordPress Site

Changing the domain on WordPress is a common occurrence, especially for developers just starting in the world of websites.

The idea is as follows: you have been working on a site on a test subdomain or on a cheap domain like .win ($3 for a year) and when the client sees the site and confirms that they like it, you need to transfer that site to hosting or to their hosting.

Let’s say you have a testsite.net and you want to change it to clientsite.com.

The proper way

is to log in to your site at testsite.net/wp-admin/.

generalwp Changing the Domain on a WordPress Site

On that page, you will see two fields with your domain (testsite.net), and you need to change them to clientsite.com and save.
This should allow you to access the new domain at clientsite.com/wp-admin/.

Check if everything is alright by opening the site and clicking on the links.

Another way

to change this is through phpMyAdmin directly in the database as follows.
Access cPanel, then click on phpMyAdmin. A new page with your database will open. Click on the database on your left side, where the tables will appear. What you need to do is find the table called

wp_options

This “wp_” is a prefix and can be wp34_ or something completely different, but focus on “_options,” which is always the same on every WordPress site. When you left-click on that table, you will see:

database domain Changing the Domain on a WordPress Site

On the right side, you will again see a link to the site testsite.net. In that row, you have Edit. Click on edit and change the site name to clientsite.com and save. Do the same for the siteurl and home fields.

After that, open the new domain, in our case klijentsajt.rs, and see if everything is fine.

The third way

is to modify the functions.php and wp-config.php files.

Log in to cPanel, then click on File Manager, then open public_html (from the left or right side, it doesn’t matter). Then, in the right half, folders will open (like wp-admin, wp-content), and among other files, there is wp-config.php.

Right-click on wp-config.php and go to edit (if a popup appears, just go to edit).

In the new tab, you will see a page with the contents of the wp-config.php file. What you need to add here is:

define('WP_HOME','https://clientsite.com');
define('WP_SITEURL','https://clientsite.com');
wpconfig domain Changing the Domain on a WordPress Site

The next file to change is functions.php. The functions.php file is located in the theme folder.

To get to your theme folder, follow the same steps as for the wp-config.php file. The folder above wp-config.php includes wp-admin, wp-content, and wp-includes. You need wp-content, open that folder, then when it opens, you need to open the themes folder. When you open the themes folder, you will see your theme folder, open that as well.

Now that we are in your theme folder, find the file called functions.php, right-click on it and go to edit.
A new tab with some codes will open, which is irrelevant for you. What you need to do is add the code

update_option( 'siteurl', 'https://clientsite.com' );
update_option( 'home', 'https://clientsite.com' );

immediately after <?php. So, literally right after that, place the mouse pointer, press enter, and then paste the two lines above that you copied. When you finish that, click on Save Changes.

The example above should look like this:

Changing the Domain on a WordPress Site

Ok. Now open your new domain, i.e., clientsite.com, and see if everything is fine; it should be. Once you’ve opened the site, go back to functions.php, right-click and edit again, and delete the two lines you’ve added and save. This is very important!

This is a substitute for the phpMyAdmin entry, and modifying the wp-config.php file is a substitute for the wp-admin general settings.

This is the procedure; however, sometimes, despite all this, it may return you to the old domain. There are many reasons, and it would not be wise to go into details now.

The solution is to use plugins.

These plugins will help you change the old domain to the new one everywhere in the database.

https://wordpress.org/plugins/velvet-blues-update-urls/
https://wordpress.org/plugins/better-search-replace/

With these, you will solve 99.9% of transfers from the old domain to the new one.

Another file you need to check if it still returns you to the old domain is the .htaccess file, located in the public_html folder (in the same place as wp-config.php).

Right-click on the .htaccess file and edit it. If it contains the old site somewhere, change it to the new one and save.

If you don’t see the .htaccess file in the public_html folder, go to the upper right corner to Settings and check Show Hidden Files (dotfiles). Then you will see the .htaccess file in the public_html folder, modify it and save.

That’s the whole procedure.

Scroll to Top