How To Change Domain Name By Editing Functions File In WordPress ?

If you are migrating to a new web address i.e. to a new domain name then there are a couple of  different methods of changing WordPress site URL. You can do it by editing your WordPress configuration file about which we have already discussed, you can do it by editing functions.php file etc etc.

If you are running a single site WordPress installation then the easiest way to change your domain address is to visit your admin area Dashboard -> Settings -> General page and change Home & Site URLs with your new domain address.

This tutorial explains you to do same by editing functions.php file present in your theme’s directory.

Open your functions.php file and add these two lines to the file changing example.com to your new domain name immediately after the initial “<?php” line.

update_option('siteurl','http://example.com');
update_option('home','http://example.com');

Load the login or admin page a couple of times till your website come back up.

Repeat the above steps, but remove those lines.

IMPORTANT: Do not leave those lines in there in your file. Remove them as soon your website is up and running again.

Leave a Reply