How to Replace old blog URL with new URL in WordPress Database

Replace old blog domain URL in WordPress Database

Davor 11/11/2019

If you decide to change your WordPress blog URL or just simply move the entire WordPress website to a new domain name, you might stumble upon the problem where old URL’s are still present in the post or page content.

How to manually replace the old URL in the WordPress database

There is a way to replace all remaining URL’s from an old domain name inside the database by querying the WordPress database. The query will find all instances of old domain name inside the posts or page content and replace it with the new domain name or URL.

Change old blog URL in WordPress database using PHPMyAdmin

All most every server has the PHPMyAdmin installed and configured. If you have the cPanel access on your hosting account, just log in and find the PHPMyAdmin and access it.

* Consider making a full database backup before you proceed.

phpmyadmin cpanel

Now access the SQL tab inside the PHPMyAdmin.

Insert MySQL query

You should paste the following code inside the SQL form field.

UPDATE wp_options SET option_value = replace(option_value, 'olddomain.com', 'newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'olddomain.com', 'newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'olddomain.com', 'newdomain.com');
UPDATE wp_comments SET comment_content = replace(comment_content , 'old_domain.com', 'newdomain.com');

After you paste this code, replace the olddomain.com and newdomain.com with the real URL. Then just hit the Go button and execute the query.

The results should confirm that the old URL’s are replaced inside the above-selected tables like wp_options, wp_posts, wp_postmeta and wp_comments.

That’s it.

How to replace the old URL or domain in WordPress using plugin

If you find the manual URL replacing too hard, you can perform the same action using a plugin. The Better Search and replace WordPress plugin offers various options to replace just about anything inside your WordPress database.

Install Better Seach & Replace plugin

To install this plugin quickly, just head to WordPress admin -> Plugins -> Add new. Once you open up this page, just type the “Better Search Replace” in the form field on the right side.

Once the plugin is listed below, click on Install and Activate.

Now, just access the WordPress admin -> Tools -> Better Search Replace.

Better Search Replace

In the first form field labeled “Search for”, paste your old domain name or URL. In the field below, marked “Replace with”, paste the new domain or URL. Then just select the desired WordPress database tables where you want to commit the changes and click Run Search/Replace.

That’s it, the old URL will be replaced with the new one right after.

Conclusion

You can use both methods or old URL or domain replacement in WordPress. The plugin approach as its the easiest and fastest way to perform search and replace. It also doesn’t require any additional knowledge.

You can also change a text or anything else using the same method as well.

Davor Veselinović

I'm Davor, founder of Worda Themes. Working as a Full Stack Developer with more than a decade of experience with WordPress. I build themes and plugins and enjoy writing useful blog posts and share my ideas with others.

Leave a Reply

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