Correcting image links after a WordPress migration

As we continue our tutorial series on migrating your WordPress site to freehostgate Hosting, the next thing we want to cover is how to update the URLS for images within your pages and posts. They are coded differently so simply changing the site URL will not fix this. In this tutorial we show you how to fix this by using your phpMyAdmin tool.

IMPORTANT! Note that this step is not mandatory. It is only necessary if your domain name is changing during the migration.

Correcting image links after a migration

  1. Log into your cPanel interface.
     
  2. select phpmyadmin toolOnce inside the cPanel, find the Databases category and click on thephpMyAdmin tool icon.
     
  3. select new databaseYou are now on the main phpMyAdmin page. Find the newly added database and click on its name from the left-hand sidebar. Our sample database is named testdb.
     
  4. select database tableThis opens the database and the screen refreshes with a list of the tables. Using the sidebar again, find and click on the wp-posts table.
     
  5. click the SQL buttonLook to the top of the screen and you will see several tabs that run across the page. Click on the SQL tab.
     
  6. enter the SQL code and run it

    You are now on a MySQL editor screen. In the code area, copy the following bit of MySQL.

     
    UPDATE wp_posts SET post_content=(REPLACE (post_content, '<old url>','<new url>'));

     

     

    Be sure to replace <old_url> with the old sitename and <new_url> with the new site name. For instance, our original site was freehostgatetesting.com and the new test site will be at test.freehostgatetesting.com so the code should appear as below:

    UPDATE wp_posts SET post_content=(REPLACE (post_content, 'freehostgatetesting.com','test.freehostgatetesting.com'));

     

     

    Click on the Go button to run the code and change the URLs for all images in the posts. This will also affect any other 'hard coded' links that were in the posts that pointed to the original site.

    Below are before and after shots of the changes made. Note that the image paths are displayed in the lower left hand corners of the images. You can see how they switched to the new sitename after the SQL code ran.

    BeforeAfter
    before the link change after the link change
     
 
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Migrating your Existing WordPress site to FreeHostGate

Section 1:   Intro to Migrating your WordPress Site Data In this article we will discuss...

Intro to Migrating your WordPress Site Data

When migrating a WordPress site from a previous hosting provider to freehostgate Hosting, there...

Migrating your WordPress Database

In this lesson, we will show you how to migrate our WordPress website. In this fictional tutorial...

Migrating WordPress Files

During the migration process to migrate your existing WordPress site from a previous host to...

Configuring WordPress After a Migration

So far in this tutorial you have migrated your WordPress database and copied the files associated...