Replace old domain URL with new one in WordPress Database

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 URLs 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 URLs from an old domain name inside the database by querying the WordPress database. The query will find all instances of the 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

Almost every server has the PHPMyAdmin installed and configured. If you have 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, '', '') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, '', '');
UPDATE wp_postmeta SET meta_value = replace(meta_value, '', '');
UPDATE wp_comments SET comment_content = replace(comment_content , '', '');

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

The results should confirm that the old URLs 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.


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.

Share this post if you like it.
Default image
Davor Veselinović

I'm Davor aka. Worda, 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 sharing my ideas with others.

Leave a Reply