I am looking to replace a few text strings for only two specific pages on a wordpress site. It should not affect those strings on any other pages. I'd prefer to do this via adding some code to functions.php

I think using part of this code would be the first part, just need help with the rest https://wordpress.stackexchange.com/a/278357

  • Welcome to WPSE. You need a little more context in your question. Based on the link it sounds like you want to change some translation strings? If so, you should specifically state that in your question. Also, a relevant example (besides just a code snippet from another question) would be helpful for anyone trying to provide an answer. That would give some context to your question. – butlerblog Nov 20 '18 at 1:24
  • 1
    You could add a filter to the_content, but it depends if you want to translate, replace the output or replace the saved content. – majick Nov 20 '18 at 2:59
  • please check this link: wp-mix.com/replace-all-instances-string-wordpress – vikrant zilpe Nov 20 '18 at 4:15

Some Example Here is how to replace all instances of a string in WordPress. Just add the following code to your theme’s functions.php file:

function replace_text($text) {
 $text = str_replace('look-for-this-string', 'replace-with-this-string', $text);
$text = str_replace('look-for-that-string', 'replace-with-that-string', $text);
return $text;


add_filter('the_content', 'replace_text');

More info on http://php.net/manual/en/function.str-replace.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.