9

WordPress写文章自动批量替换或删除内容里的文字

 2 years ago
source link: https://www.huhexian.com/21508.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WordPress写文章自动批量替换或删除内容里的文字

青山 2022-01-0514:24:55评论592字

我们在做网站SEO优化更新发布Wordpress文章的时候,是不是会遇到复制别人网站的文章时携带了一些别人的品牌词或者别人的相关内容,这个时候我们在发布每一篇文章的时候都需要注意修改调整从而给自己的发布带来不便降低了工作效率,这个时候要是可以自动遇到这些关键词或者内容的时候转换替换成我们自己想要的文字就方便多了,再或者尤其是网站内容达到几千上万篇的时候,一篇一篇手动删除修改太麻烦了。那么下面我们分享一下我们的处理办法:

WordPress写文章自动批量替换或删除内容里的文字

在当前的WordPress主题或子主题中的 functions.php 函数文件中添加如下代码:

  1. //发布文章自动替换相关内容
  2. function replace_text_huhexian($text){
  3. $replace = array(
  4. //'关键词' => '将要替换的关键词'
  5. '例子' => '案列',
  6. 'wordpress' => 'wordpress主题',
  7. $text = str_replace(array_keys($replace), $replace, $text);
  8. return $text;
  9. add_filter('the_content', 'replace_text_huhexian');
  10. add_filter('the_excerpt', 'replace_text_huhexian');

按照上面的方法就可以了,是不是很简单快速呢?上述如果还有更多关键词替换需要自行增加。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK