热爱生活
有活就干!

批量替换WordPress文章中的文字

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

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

  1. function replace_text_wps($text){
  2.     $replace = array(
  3.         // ‘关键词’ => ‘替换的关键词’
  4.         ‘WordPress‘ => ‘<a href=“#”>wordpress</a>’,
  5.         ‘excerpt’ => ‘<a href=“#”>excerpt</a>’,
  6.         ‘function‘ => ‘<a href=“#”>function</a>’
  7.     );
  8.     $text = str_replace(array_keys($replace), $replace$text);
  9.     return $text;
  10. }
  11. add_filter(‘the_content’, ‘replace_text_wps’);
  12. add_filter(‘the_excerpt’, ‘replace_text_wps’);

 

赞(0)
未经允许不得转载:有货街 » 批量替换WordPress文章中的文字

相关推荐

  • 暂无文章