WordPress has a nasty habit of storing absolute URLs in the database.  That means that all internal paths, including images and other resources are stored in the database containing the base URL of your blog alongside the URI of the resource. It is not possible to change WordPress URL quickly. Or at least I thought so.

For years, I’ve been changing WordPress URL in the same way – export the database, search/replace old URL with new one in the SQL file, then import changed SQL file. And it worked. It was not quick, but it worked. Then, one day, I needed to change WordPress URL, but I didn’t have access to database. So, I decided to look for another solution. And, voilà, I found out that it can be done just by adding two lines of code!
There are actually several ways to do this. But easiest by far is to add these two lines to the beginning of the active theme’s functions.php:

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

Then, all you have to do is to load the login or admin page a couple of times. The site should come back up. And, it’s done! Amazing!

All of this time I was doing it the hard way. And I was teaching people to do it like that. Anyway, this is a good lesson that from time to time, person should question the way he does things and try to find out a better, more efficient solution. Who knows what we could accomplish if we did that more often.

For further reading, I recommend official WordPress codex page with all the different ways to change the URL or migrate the site explained in details: https://codex.wordpress.org/Changing_The_Site_URL