Change image URL in WordPress database

Many users choose to host their images on an external service to reduce the load on their hosting. If you are interested in doing this, you will only have to change the location of all the images that you have already uploaded.

To do this, you need to make two SQL queries in your database:


1. For images inside posts:

UPDATE wp_posts SET post_content = REPLACE (post_content, 'src="//www.old-url.com', 'src="//new-url.com');

2. For images linked as attachments:

UPDATE wp_posts SET  guid = REPLACE (guid, 'https://www.old-url.com', 'https://new-url.com') WHERE post_type = 'attachment';

Was this post helpful?

Leave a Comment