We’ve all had web design situations where we’ve needed to replace a snippet of text throughout our website. The task of learning how to replace text is a literal right of passage for most new WordPress designers.

And I use the term “right of passage” in regard to Googling the term, “how to replace text within WordPress.” In running that search, you’ll likely find yourself going down so many knowledge rabbit holes that you may forget what you were searching for in the first place. Been there!

Nowadays, I use the uber awesome plugin, Better Search Replace. I mean it simply does the job so elegantly I sometimes forget there were alternatives.

Back in the day, before search and replace plugins were a thing, I recall using a simple bit of text that was all the rage back in 2013. I was a big fan of The Web Taylor Hampshire blog back then and recall geeking out with his blog on numerous occasions. One of the blog posts discussed WordPress: Replace string in content of all pages, gave the following functions.php ready snippet:

function replace_content($content)

{

$content = str_replace('##Replace Me##', '##With Something Else##',$content);

return $content;

}

add_filter('the_content','replace_content');

All one had to do was add this bit of text, with the appropriate amendments to a WordPress theme’s functions.php file and boom!—like magic, all was well in the Universe once again.

So if you find yourself about to go down that “how do I replace text in WordPress?” hole possibly occupied by a small furry varmint, well, now you know how.

Enjoy!

Share me please: Tweet





Print



Like this: Like Loading...