在word软件中,有替换词语这个功能,把不符合写法的,或者错的字词统一替换掉,在wordpress的日志中,我们也可以实现这个操作,不过要使用代码,把下段代码放在functions.php中,使用add_filter过滤the_content和the_excerpt,这样所有的相关词语就被替换成你想要的。 

在word软件中,有替换词语这个功用,把不符合写法的,或许错的字词一致替换掉,在wordpress的日志中,咱们也能够完成这个操作,不过要运用代码,把下段代码放在functions.php中,运用add_filter过滤the_content和the_excerpt,这样一切的相关词语就被替换成你想要的。

如安在日志中统一替换字词  使用技巧 字词 日志 替换 新闻资讯 第1张

1 function replace_text_wps($text){
2 $replace = array(
3 // 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
4 'wordpress' => '<a href="#">wordpress</a>',
5 'domain' => '<a href="#">domain</a>',
6 'excerpt' => '<a href="#">excerpt</a>',
7 'function' => '<a href="#">function</a>'
8 );
9 $text = str_replace(array_keys($replace), $replace, $text);
10 return $text;
11 }
12
13 add_filter('the_content', 'replace_text_wps');
14 add_filter('the_excerpt', 'replace_text_wps');

转载请说明出处
知优网 » 如安在日志中统一替换字词

发表评论

您需要后才能发表评论