Change WordPress Domain Name with Elementor Content 更改有Elementor内容的WordPress站点地址

Table of Contents

It is a pain in the a** to change a WordPress site’s address or URL, more so if you use Elementor. Elementor stores text differently than vanilla WordPress. In order to migrate a WordPress site with Elementor-created content to another domain name or URL, following steps were executed.

Backup Database 备份数据库

You can use your trusted database management tools to back up database. Or a SQL dump file can be generated by using the following command under linux:

mysqldump -uyouruser -pyourpassword wordpress > wordpress.sql

Replace youruser with your MySQL user name, yourpassword with your MySQL password, and database name with you actual database name if it is not “wordpress“. The command create wordpress.sql at current directory, which can later be imported into MySQL if things go wrong.

Modify Database to Change Domain Name 修改数据库中域名

Next step is to alter the database content to change all old domain name to new domain name. The following SQL queries update wordpress internal data about site URL.

UPDATE `wp_options` SET `option_value` = 'newUrl' WHERE `wp_options`.`option_name` = 'siteurl';
UPDATE `wp_options` SET `option_value` = 'newUrl' WHERE `wp_options`.`option_name` = 'home';

UPDATE wp_posts SET guid = replace(guid, 'oldUrl', 'newUrl');

UPDATE wp_links SET link_url = replace(link_url, 'oldUrl','newUrl');

The following updates URLs in post bodies. However, if your URL has sub directory these queries will not match.

UPDATE wp_posts SET post_content = replace(post_content, 'oldUrl', 'newUrl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'oldUrl','newUrl');

If sub directory is involved, you need to use the following SQL queries as elementor use \ to escape /, and SQL use \ to escape \, so for every / in actual text, a \\/ is used in SQL query:


UPDATE wp_postmeta SET meta_value = replace(meta_value,'http:\\/\\/oldUrl\\/path','http:\\/\\/newUrl\\/path');

UPDATE wp_posts SET post_content = replace(post_content, 'http:\\/\\/oldUrl\\/path', 'http:\\/\\/newUrl\\/path');

You need to run both of the above queries as both WordPress and Elementor content needs to be updated.

Restore Database 还原数据库

If you used mysqldump to backup MySQL, pipe the file into MySQL will restore its content.

mysql -uyouruser -pyourpassword wordpress < wordpress.sql

Replace youruser, yourpassword and database name accordingly. You may need to clear out the database before proceeding with restoration.

Leave a Reply

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