Slider Revolution demo screen

Run a WP-CLI Search-Replace for Revolution Slider

If you’re a WordPress developer moving sites between environments, you might find yourself using the WordPress command line tool WP-CLI to run database search-replaces fairly frequently. This lets you quickly swap out one URL for another in the database (so if I want to replace https://sternerstuff.dev with https://sternerstuffdesign.test, for local testing).

I inherit a variety of sites using Revolution Slider (RevSlider, Slider Revolution, whatever). It’s bundled with pretty much every bloated ThemeForest theme and for the most part, I don’t recommend it. But sometimes, it’s more prudent to maintain the work that’s been done than rip it out.

RevSlider saves URLs for any images and links in its slides with escaped backslashes. So in the database, a URL might look something like https:\/\/sternerstuffdesign.com\/wp-content\/uploads\/2019\/01\/image.jpg. And the WP-CLI search-replace command won’t catch these (issue report), so your URL references in RevSlider still point to the previous environment.

This isn’t a big deal from production to test, but if an image exists on my test environment but not production, and the reference makes it to production, the world wide web won’t be able to follow the link or see the picture.

Revolution Slider Search Replace

Fortunately, some good soul wrote a WP-CLI package to handle this. You can find it here, and by installing it, it allows you to run something like the following:

wp rsr all https://sternerstuffdesign.test https://sternerstuff.devCode language: Bash (bash)

And it works like a charm. Try it out if you’re in this spot.


Leave a Reply

Your email address will not be published. Required fields are marked *