Replace URL in WordPress Posts, Images and Links

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

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 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 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 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.
  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 and 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.

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

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

You might also like

How to Redirect / Forward Entire WordPress Blog Hackourlives...
WordPress Blog Post by Post Redirection! You recently...
Best Featured Posts / Content Slideshow Plugin for WordPress While there...
Linux Command to Fix Permissions for Files and Directories If you migrate...

About the Author

has written 346 posts on this blog.

Meditating towards his "nerdvana", lifehacker is a teacher by the day and a nerdy blogger by the night. He lives to learn and yearns to learn living.

3 Comments on “Replace URL in WordPress Posts, Images and Links”

  • Furrionuvx wrote on 28 March, 2019, 3:36

    ???????,??????????! .

    Like or Dislike: Thumb up 0 Thumb down 0


  • Artisanvdm wrote on 28 March, 2019, 14:56

    ???????,??????????! .

    Like or Dislike: Thumb up 0 Thumb down 0


  • RainMachinewoy wrote on 29 March, 2019, 5:56

    ???????,??????????! .

    Like or Dislike: Thumb up 0 Thumb down 0


Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!


Copyright © 2019 Hack Your Life!. All rights reserved.
Proudly powered by WordPress. Developed by Deluxe Themes