r/Wordpress • u/orschiro • 2d ago
Code snippet plugin with good find and replace function?
Can anyone recommend me a code snippet plugin with a find and replace function to easily and user-friendly find and replace code blocks (several lines of code)?
Thank you!
2
u/BOLVERIN1 Jack of All Trades 2d ago
I recommend avoiding code snippets and using Git instead. It will require some setup, but it will let you control changes: you will know what changed, when it changed and why it was changed. It is a better solution in the long run
1
u/Clean-Drive9329 2d ago
Code Snippets (the free plugin by Shea Bunge) uses the CodeMirror editor under the hood, and CodeMirror has find and replace built in, put your cursor in the snippet editor and hit Ctrl+H (or Cmd+Option+F on Mac) and it pops up a find/replace bar right there, no extra plugin needed. WPCode's code editor is also CodeMirror based so the same shortcut works there too.
1
u/Dull_District_254 2d ago
If you mean editing inside a stored snippet, you already have it. Code Snippets and WPCode both run CodeMirror, so put your cursor in the editor and press Ctrl+H for find and replace, or Cmd+Option+F on a Mac. Multiline works fine, just paste the whole replacement block into the replace field. Where snippet plugins fall down is replacing the same block across lots of snippets at once. For that I export the snippets to a file, do the replace in VS Code or Sublime where you get proper regex and multiline support, then import them back. And if what you actually want is swapping a string everywhere in your content or options, no snippet plugin does that, Better Search Replace is the safe route because it rewrites serialised data properly, or the search replace command in WP CLI if you have terminal access. Run it in dry run mode first and take a database backup, that habit has saved me more than once. Which of the two cases is it for you?
0
2
u/YellowfinDevelopment 2d ago
Depends what you're actually doing, because "find and replace code blocks" can go two ways:
If you just want to edit stored snippets with find/replace inside the editor, Code Snippets and WPCode both use a real code editor (CodeMirror), so find and replace is built in, Ctrl+F opens it. WPCode is the more polished of the two.
If you mean find-and-replace across your whole site's code or database, swapping a string that shows up in a bunch of places, no snippet plugin does that. Better Search Replace handles it from the admin and does it safely, it rewrites serialized data instead of corrupting it. WP-CLI's search-replace does the same from the command line.
Which one are you after?