How to Change A WordPress Site URL Using A Function

Sometimes you may need to change the URL of your wordpress site. for example, its a common practise to develop the new version of your site in a Subfolder and when it is ready to move into your root directory. wordpress, however relies on its URL Settings to work correctly, This means that if you simply move your files database it will not work properly. The URL Settings are located in The application database. fortunately, direct a database modification can be avoided by using a nice function provided by the wordpress developers named “update_option” simply add these lines to the Functions.php file of
your theme:


update_option
('siteurl','http://www.your-new-site-address.com');
update_option ('home','http://www.your-new-site-address.com');

Then simply load your site from its new location – its should work
just fine.
Note that, after you run your site once and you make sure it works you should delete these lines from your functions.php file because, the settings are already stored in your database and should not be modified each time your site is loaded.
Hope you find this tutorial useful incase you considering changing your wordpress url.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address