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 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 WordPress.org site, which I have modified a bit to make it more clear. Lets first fix all the URL entries in the database.
- Login to phpMyAdmin.
- Click the link to your Databases.
- A list of your databases will appear. Choose the one that is your WordPress database.
- 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.
- Clicking the Browse icon or link, open the wp_posts table.
- Look for the field that holds your post “guid”. It is usually called guid, but it may have been changed. Write it down.
- Click the tab at the top for SQL.
- 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 ( guid, 'http://exampleoldsiteurl.com', 'http://examplenewsiteurl.com');
This is how it should look before you click on go.
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 ( post_content, 'http://exampleoldsiteurl.com', 'http://examplenewsiteurl.com');
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...|