Don't waste your time, use Search Regex

Search Regex is an amazing free WordPress plugin that enables you to search and replace code throughout your WordPress site. It can save an insane amount of time if used properly. The use cases for it are countless. To give you an idea of how useful it can be and inspire you to think about how you can leverage the tool, I’ve provided some specific examples of how I’ve used it below.


Select entire shortcode

Search pattern

[\[yourshortcode.*\]]
Select entire button shortcode with Search Regex

The above search pattern will return all instances of shortcodes on your site. This could be useful if for example, you wanted to remove legacy shortcodes throughout your site.


Add a shortcode surrounding all images

Search pattern

[<img(.*?)>]

Replace pattern

[yourshortcode]<img$1>[/yourshortcode]
Add shortcode surrounding all images with Search Regex

The above example would add the Elegant Themes social share media shortcode for the Monarch social media sharing WordPress plugin to all images on your site. Just imagine how much time it would take to do that manually for 353 images!


Remove all links to a particular domain

Search pattern

[<a(.*?)href="(.*?)://domain.com/(.*?)>(.*?)]

Replace pattern

$4
Remove all links to a domain with Search Regex

The above example would select all links pointing to domain.com and remove the links while keeping the anchor text, effectively removing all links on your site pointing to domain.com.


Convert shortcode buttons to HTML buttons

Search pattern

[\[yourshortcode title="(.*?)"(.*?)href="(.*?)"\]]

Replace pattern

[<a href="$3" class="button color-3 large">$1</a>
Convert shortcode buttons to HTML buttons with Search Regex

The above example would convert all visual composer buttons from shortcodes to HTML buttons. It simply moves the link URL and the anchor text to the correct position in the new link tag and adds the classes used for the HTML button.


Other uses for Search Regex?

If you need help figuring out how to use it effectively on your site, let me know what you want to do in the comments and I’ll see if I can help you do just that. If you have other ways to use this amazing plugin I’d love to hear about them!

6 COMMENTS

  1. Visual Composer is a massive headache, 3000 post site previously using it leaves alot of crap to clean up. Would be great to find a a post to ragex all visual composer short codes to foundation equivalent shortcodes.

  2. Ah, very useful indeed. I also found this user guide on the WordPress forum. Maybe this can help other users who used this plugin too!
    Wordpress.org/support/topic/additional-usage-notes

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.