How to Fix Image Links after a WordPress Migration Using phpMyAdmin

Website migration can be overwhelming, and most of the time, it can affect images, which lead to the broken image links.

When you either change your web hosting company or move the WordPress installation from one folder to another, you require to take care of the interlinks and images.

If you don't change the domain name, which means if you transfer your website from one server to another, you can fix the interlinks and images by changing the website address in your wp-admin panel.

But when you change the domain name, location or the WordPress installation, you may in need to update the URL for all the posts.

In most cases, you require to update the URL, it may be using the wp-config.php file or wp_options database table, but if you get broken image links, you need to update the URL for your blog posts.

I am going to walk you through the process.

You Have to Deal With the SQL Query

As you know, WordPress runs the MySQL database. So to make any changes in the database tables, you require to add an SQL query.

Don't worry; I am not asking you do it yourself, I am going to provide the answer to your question.

I hope you know how to access your website's database. If not, you need to use cPanel. Well, if you're wondering about why every time you try to accomplish something, you need to deal with cPanel.

Well, cPanel offers some fantastic features to manage your site, try to learn it.

Follow the steps.

Step 1:

First of all, you need to open your cPanel account and search for the phpMyAdmin icon under the Databases section.

How to Fix Image Links after a WordPress Migration Using phpMyAdmin

If you don't see the same layout, it's because every web hosting company offers a different cPanel template. But don't worry, you can easily find the similar option.

Step 2:

In this new tab, you can see phpMyAdmin. You have to open the database by selecting the name from the left-side sidebar.

How to Fix Image Links after a WordPress Migration Using phpMyAdmin

I hope you know the database name, if you don't, you need to go back to see the database wizard, which consists all the databases' name.

Step 3:

Once you open the database, you can see tons of database tables. From which, you require to open the wp_posts table.

How to Fix Image Links after a WordPress Migration Using phpMyAdmin

Note: wp_ is the default database table prefix, your database may differ because, for security reasons, it's necessary to change the default database table prefix.

Step 4:

Now is the time to open the MySQL editor, click on the SQL link showing on the vertical navigation menu of phpMyAdmin.

How to Fix Image Links after a WordPress Migration Using phpMyAdmin

Step 5:

You can see a box to add the query. Let me show you the structure of the SQL code.

UPDATE wp_posts SET post_content=(REPLACE (post_content, '',''));

But, it's not enough, you have to add your both the domain names. For example, if the old URL is, and the new URL is

The code becomes.

UPDATE wp_posts SET post_content=(REPLACE (post_content, '',''));

How to Fix Image Links after a WordPress Migration Using phpMyAdmin

The code means that all of your posts links have been replaced with your new URL. The above example shows the migration from the primary domain name to a subdomain.

Click on the Go button to run the code.

Congrats, you have successfully replaced your blog posts images' links. Sometimes, it can be hectic because of the hard-coded links.

Mostly, when people have an affiliate website, the interlinks can be hard to redirect to a new URL, but the SQL query takes care of everything.

I Hope You Can Manage to Run an SQL Code

I remember when I migrated a website from one domain to another, I tried to change the site URL from all the places but could succeed.

For blog posts, modifying the images link using SQL is a perfect idea. You may not need to use it every time you transfer a website.

As you can read above, you might need it when you see broken images in your blog posts. Otherwise, everything is fine.


Fixing the broken images links is an advanced way to tackle a WordPress issue, not everyone knows it. I hope you have learned the correct way to accomplish such a task.

Sometimes, you can encounter with broken images links because of the CDN you use; be careful before you run an SQL query.

Check out these top 3 WordPress hosting services:

Was this article helpful?