How to update your wordpress site urls after move on other server?

Hello Friends!
I hope you all are enjoying my previous post 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.
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

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', '' );
update_option( 'home', '' );

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.

Leave a Reply

Your email address will not be published. Required fields are marked *