How to quickly search and replace any HTML/text on a WordPress website?
We’ve got a client website that’s about to go out the door in the next 48 hours. The site has got around 75 webpages, and noticed that the copy on one page needs to be duplicated to all other pages. Arrrghh …
Now, we’re running a WordPress setup with multiple sites on all our servers (development, staging and live) and a lot of the WordPress search and replace plugins assume you only have one website/blog.
So … the easy way … stop searching for the perfect WordPress plugin and follow these simple steps –
- Pull up phpmyadmin
- Find the correct site/blog you’re wanting to update – in my case, it’s site # 16
- Go to the SQL tab and enter the following statement (where wp_16_posts uses the 16 corresponding with the correct site above!) –
SET post_content = replace(post_content, "Old text here", "New text here")
- Now the nice thing is, the replace function can be built up of anything that’s in that post (or anywhere else in the database for that matter, but let’s keep it simple) … for instance –
UPDATE wp_16_posts… would take the post title, and replace the h1 Dummy heading text with the post title.
SET post_content = replace(post_content, "<h1>Dummy heading</h1>", concat("<h1>", post_title, "</h1>")
Hope that helps someone out there looking for a quick, down and dirty, search and replace for WordPress!