Quickly Search and Replace a Text or Image or URL in WordPress Post Contents

Updated on September 2, 2017

Do you want to search and replace a particular URL or text or an image in WordPress post contents? For example, I recently switched my WordPress site from ‘http’ to ‘https’ protocol and left with few issues. One of the issue is – most of my old posts were embedding YouTube video via http URLs. For e.g, http://www.youtube.com/embed/<id>. After the site was migrated to https, the web browser refused to load the video content with the warning as ‘Mixed contents’. It means that the site is served via https and the loaded YouTube video was http. So, I wanted to perform a mass search and replace all http URLs with https (only youtube) in post contents.

Note: The following steps will help you to replace any text, or name of an image and URLs.

How to search and replace all URLs in Post contents using MySQL Query

Warning: Remember to take a backup of your WordPress database before following the below steps.

1. Login to MySQL database

2. Run the below query:

update wp_posts set post_content = replace(post_content,'http://www.youtube.com','https://www.youtube.com');

The above query is meant to replace all http URLs of youtube with https. In a similar way, you can search for a particular text and replace as shown below:

update wp_posts set post_content = replace(post_content,'pattern_to_search_for','text_to_be_replaced');

Not confident in executing a MySQL query? Then you can try this plugin – Better Search Replace.

search and replace text

Was this article helpful?

Related Articles

Leave a Comment