简体   繁体   中英

Find and replace text from Html with PHP, Wordpress

I need to find and replace text from all pages from a Wordpress site. This text shows in header as well, I tried this in functions.php but not working:

function replace_text($text) {
$text = str_replace('word1', 'word2', $text);

return $text;
}
add_filter('the_content', 'replace_text');

Anyone can help with this? Thanks

You have to pass exact parameters in call of function that are in function definition, call function like its name,

$data = "sdfsdfdsfwf"
$result = replace_text('find what you want to replace', 'replace with', $data);
echo $result;

Then in the definition of function name is same as the method call and parameters count is same as in call of method.

function replace_text($find, $replace, $data) {
   $text = str_replace($find, $replace, $data);

   return $text;
}

returned result contain replaced string.

want to know more about str_replace check this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM