wp-content » plugins » How to change domain name for a WordPress website (5 ways)

How to change domain name for a WordPress website (5 ways)

Want to change the domain name for your WordPress website? No problem, in this guide We’ll walk you through 5 different methods to change the domain name for a WordPress website from cPanel PHPMyAdmin.

Before following this guide make sure you’ve down the following:

  • registered the desired domain name and pointed it towards your hosting package
  • added it on your cPanel account as Addon domain

Go to your wp-admin dashboard and under Settins change the domain name for the following fields:

  • WordPress Address (URL)
  • Site Address (URL)
check - How to change domain name for a WordPress website  (5 ways)

Make sure to double-check the domain name and click on Save Changes afterward.

To add a domain name to cPanel, got to Addon Domains.

addon domeni - How to change domain name for a WordPress website  (5 ways)

If the domain name is already added, simply change the Document root for it to point it to the already existing installation of WordPress.

promena - How to change domain name for a WordPress website  (5 ways)

Click on the pencil icon next to the Document root path to change it.

prozor - How to change domain name for a WordPress website  (5 ways)

After changing the path click on the Change button to save new path.

One of the most popular plugins to change a domain name in WordPress is Search & Replace.

chrome NgY90KKbBc - How to change domain name for a WordPress website  (5 ways)

To install this plugin head over to Plugins > Add New.

novi sistem - How to change domain name for a WordPress website  (5 ways)

Search for “search replace” and install then activate the plugin:

instaliranje plugina 1024x428 1 - How to change domain name for a WordPress website  (5 ways)

To access the plugin Search & Replace go to Tools > Search & Replace

search replace plugina - How to change domain name for a WordPress website  (5 ways)

Before changing the domain name I recommend making a database backup (export) from the Backup Database page by clicking on the Create SQL File button.

bekap baze - How to change domain name for a WordPress website  (5 ways)

Afterward on the page Replace Domain URL in the field Search for: put the current domain name and in the field Replace with: put the new doamin name. You can also use URL with http:// or https:// prefix.

zameni u bazi - How to change domain name for a WordPress website  (5 ways)

And finally click on the Do Replace Domain/URL button.

The plugin will search and replace the old domain name with the new one in the entire database. After it’s finished you can start using the new domain to enter wp-admin dashboard.

First to identify your database, open the wp-config.php file and under DB_NAME check the name of the database that your WordPress website is using.

baza - How to change domain name for a WordPress website  (5 ways)

From cPanelnavigate to PHPMyAdmin.

phpmyadmin - How to change domain name for a WordPress website  (5 ways)

After PHPMyAdmin loads up on the left side of the screen, you will see a list of all databases, make sure to select the database name as written in your wp-config.php file.

moja baza - How to change domain name for a WordPress website  (5 ways)

You will see a list of all the tables in this database. Find the table wp_options – the prefix for this table is also defined in the wp-config.php file under table_prefix.

prefix - How to change domain name for a WordPress website  (5 ways)
opcije - How to change domain name for a WordPress website  (5 ways)

Click the pencil icon Edit before values siteurl and home – then change the domain name.

jedan - How to change domain name for a WordPress website  (5 ways)

Under option_value change the domain name and when you are done click on the Go button at the bottom of the page.

promena adrese u bazi 1024x400 1 - How to change domain name for a WordPress website  (5 ways)

Do the same for the home option as well.

See also  How to fix Call to undefined function get_magic_quotes_gpc() in WordPress ✔️

NOTE: After changing the domain name directly in the database it’s important to log into wp-admin dashboard under the new domain name and underSetting > permalinks click on the Save Changes button to regenerate all links in the database.

In this advanced method, we will use the built-in update_option function to change a domain name for a WordPress website. By using this function we will rewrite the site_url and home settings in the database.

After adding the following code inside your active theme’s functions.php file, access the website using the new domain name, to make sure everything is working as expected, and then make sure to delete the code from the functions.php file.

Open your functions.php file (I suggest making a Child theme first) and add the following code right under the first line with<?php

update_option('siteurl','https://new-domain-name.com');
update_option('home','https://new-domain-name.com');

The beginning of the file should look like this:

chrome ibktc5WJaM - How to change domain name for a WordPress website  (5 ways)

After making changes make sure to click on the Save Changes button in the top right corner.

chrome PHJOejW4Um - How to change domain name for a WordPress website  (5 ways)

After saving changes, access the website under the new domain name and change back the functions.php file as it was – delete the above added lines.

Similar like the previous method, we will edit one of WordPress’s main config files – wp-config.php and in it set new values for site_url and home settings.

Open wp-config.php file and add the following code at the beginning just after <?php

define('WP_HOME', 'https://new-domain-name.com');
define('WP_SITEURL', 'https://new-domain-name.com');

The beginning of the file should look like this:

chrome y7GsQbRvSR - How to change domain name for a WordPress website  (5 ways)

After making changes make sure to click on the Save Changes button in the top right corner.

chrome PHJOejW4Um - How to change domain name for a WordPress website  (5 ways)

NOTE: By using this method we are overwriting the domain name in WordPress, and you won’t be able to change it from the wp-admin dashboard until you remove these lines from the wp-config.php file.

To change a domain name for a WordPress website we need to do several things:

  • Register a new domain name
  • Point it to your hosting using nameservers
  • Set the Root Directory towards the WordPress files
  • Change site address in the database

As always, before making any changes to your WordPress website I suggest making a full backup of both files and the database.

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended