批量替换WordPress文章中的文字

如果你在博客的文章中经常加入一些关键词句,但后来准备将这些关键词句替换为其它的内容,手动替换工作量大、而且麻烦。下面的段代码可以非常方便地帮你替换掉这些关键词句。

将下面代码加到主题的functions.php文件中:

function replace_text_wps($text){
 $replace = array(
 // '关键词' => '替换的关键词'
 'wordpress' => '<a href="#">wordpress</a>',
 'excerpt' => '<a href="#">excerpt</a>',
 'function' => '<a href="#">function</a>'
 );
 $text = str_replace(array_keys($replace), $replace, $text);
 return $text;
 }

add_filter('the_content', 'replace_text_wps');
 add_filter('the_excerpt', 'replace_text_wps');

原文:How to easily replace words in your posts