Hello Friends!
I hope you all are enjoying my previous post https://www.wp-experts.in/blog/2013/12/24/how-change-and-update-wordpress-urls-in-database-when-site-is-moved-to-new-host/ that i had posted it few year ago.
During setup of wordpress site from "Local Server" to "Live Server", we always need to update the site & home url of the website as per new domain url. There are three way for update to the site url after move site on other server.
1.) You can directly run given below mysql query from phpmyadmin
/** update URL in options table **/
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
/** update URL in posts table **/
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
/** update URL in posts table **/
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
/** update URL in postmeta table **/
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
NOTE : Here we are using "wp_" as prefix of the tables, In your case, it might be different, so please don't forget to update it's value as per your database before run mysql query. You can find out the prefix of the table from wp-config.php file, just find "$table_prefix" variable in your website config.php file.
[youtube https://www.youtube.com/watch?v=qCQgpFjLjfg?autoplay=1]
2.) You can define site and home url directly through the wp-config.php file , just add given below code into wp-config.php file
/** Define site URL
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
3.)You can also update site and home url through theme function.php file, just add given below two lines to the file, immediately after the initial "<?php" line.
update_option( 'siteurl', 'http://example.com' );
update_option( 'home', 'http://example.com' );
I want suggest you to choose first way becuase second and third one have a drawback. Drawback is that it will update permalink urls only not images/links that have saved into database.