Batch changing URL of post images in wordpress

For blogger who self-hosts the WordPress blog publishing system on a web hosting server with own registered domain name, sometimes, you may decide to reorganize the blog link URL to make it tidier or to reflect new focus or theme of the blog. You may decide to change URL of your site as well. But changing URL can cause some issues. You may face broken images in all your previous posts since you just changed URL of site but didn’t update the URLs for images already added to posts.

e.g Before changes, your wordpress URL was: & your images URL were like:
And After Change, your site URL is: but your all posts are showing images from

It’s not possible to correct URL of all images by editing each post since it can take too much time based on volume of site. A better approach is to Change URLs of all the images collectively by SQL Querying the database. Let’s see how easy it this below:

NOTE: We will be using SQL statements based on MySQL replace() function to modify the database. To run SQL queries, you need to login to MySQL database that houses WordPress tables via phpMyAdmin or login to the DB server and run MySQL client as root. If you don’t have access to it, then you can also do this from your wordpress admin dashboard by installing a plugin: Find & Replace ( )

Go to MySQL Query mode & use the following SQL commands to fix broken links to blog in all WordPress posts and pages:

-- MySQL Query

UPDATE wp_posts SET post_content  =
replace(post_content, '', 'http:/');

-- see documentation of replace function for more understanding

The above SQL Query will replace all the links for with in post_content (DB Table that stores all posts content) & hopefully this will fix broken images links as well since now those images URLs will be changed to new domain.

Caution: Before making changes to database & run queries, make sure to backup your database because these changes will be permanent and can’t be undone. Dont forget to export your database from phpmyadmin as .sql 

Please share this with others who are facing such issues – Sharing is Caring..

Tagged with: , , , , ,
Posted in Tutorials, Wordpress

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: