Updating URL’s in the database after WordPress migration

A screenshot of phpmyadmin showing the code you need in order to update URL's across a database

When you move a WordPress site from one domain or environment to another (like from staging to live) you’ll often find hardcoded URLs left behind. These can break links, images, or even cause login issues if not handled properly.

I’ve done a lot of WordPress migrations over the years, and updating the database correctly is always part of the process. In this post, I’ll share how I handle URL replacements safely and efficiently, and which tools I use to avoid problems with serialised data or hidden content fields.

Updating the URL’s in phpmyadmin

Once you’ve imported your database into phpmyadmin, you’ll want to navigate to the SQL tab (see image below)

SQL tab within phpmyadmin

Then you’ll want to paste in the following code:

UPDATE wp_options SET option_value = replace(option_value, 'https://oldurl.com', 'https://newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'https://oldurl.com','https://newurl.com');

UPDATE wp_posts SET post_content = replace(post_content, 'https://oldurl.com', 'https://newurl.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://oldurl.com','https://newurl.com');

You’ll need to replace the https://www.oldurl.com and https://newurl.com with your own URLs (don’t include trailing slashes).

Then press ‘Go’ and it should let you know how many rows it has replaced the URL in.

That should be it!

A migration shouldn’t mean hours of broken links or manually fixing content. With the right approach, updating URLs in the WordPress database is quick, safe, and repeatable.

If you’re preparing for a migration or dealing with post-move issues, I can help. Whether you’re switching domains, going live, or just reorganising, I’ll make sure everything stays working smoothly.

Drop me a message if you’d like support with your WordPress move.


Leave a Reply

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

Let's talk

Whether it’s a small step or a giant leap, I’m here to guide your project.

Make contact