- Hack Your Life! - http://www.hackourlife.com -

Replace URL in WordPress Posts, Images and Links

If you migrate your website to a new domain or location, you might need to fix (replace) all the hard coded links and URLs in your posts, also you would observe that all the images links point to your old address. All these things can be fixed easily.

Method 1: Using phpmyadmin via direct modification of the database

This is easier than it appears to be, you need the access to your database via phpmyadmin. Procedure is simple and clean. Before you begin you must back up your database [1] and save the copy off-site (The following is irreversible. There is no “undo” or “undelete” button. This is permanent. Be warned that it can do harm.). Actually you should create a duplicate of the database and then do all these operations on the duplicate database, if things don’t go well, you can always revert back to the original database (by duplicate I mean download the backup and then restore the backup [2] to another empty database). You can make WordPress to use the duplicate database by changing the database name in wp-config.php file in your root directory. The content given below has been taken from WordPress.org [3] site, which I have modified a bit to make it more clear. Lets first fix all the URL entries in the database.

  1. Login to phpMyAdmin.
  2. Click the link to your Databases.
  3. A list of your databases will appear. Choose the one that is your WordPress database.
  4. Look for the name of the table within your database used to hold your post information. Usually it is calledwp_posts, but it may have been changed (if you changed the table prefix during the install). Write it down.
  5. Clicking the Browse icon or link, open the wp_posts table.
  6. Look for the field that holds your post “guid”. It is usually called guid, but it may have been changed. Write it down.
  7. Click the tab at the top for SQL. [4]
  8. Using the information you wrote down from above and the old and new URL addresses you wish to update or search and replace within your database, type in the following (CAREFULLY). Before that, make sure that you have clicked on wp_posts table, it can be seen highlighted on the menu on the left.


Now enter the following command in the SQL queries box (make sure you replace exampleoldsiteurl.com and examplenewsiteurl.com to suit your needs. This command searches for first string in guid and replace it with the second string.

UPDATE wp_posts SET guid = REPLACE (

This is how it should look before you click on go.

[6]It would check and replace all instances of the string1 with string2.

Now we can use this same approach to fix all the image and URLs pointing to your old domain, by running the following command (this command would replace all content with string1 with string2 in table wp_content

UPDATE wp_posts SET post_content = REPLACE (

It should look something like this, hit Go to replace all content.


This should fix all post and image links. Let me know if anything is not clear, or if you encounter any issues.

Method 2: Using a plugin like Search and Replace [8]

I haven’t tried it yet, but if the direct modification of database seems intimidating to you, you can give it a try.