批量替换wordpress文章内容的方法

可有两种方法实现替换wordpress的文章内容,一是从更新数据库,二是在 WordPress 主题中实现

方法一、更新数据库

进入 phpmyadmin,找到wordpress的数据表,先备份,然后执行如下SQL语句:

UPDATE wp_posts SET post_content = replace(post_content, 'old','new');

其中 old 是旧的字符串,new 是你要替换的文字。

方法二、从 WordPress 主题下手

在 WordPress 主题的 functions.php 中插入如下代码:

function content_str_replace($content = ''){
	$content = str_replace('old', 'new', $content);
	return $content;
}
add_filter('the_content', 'content_str_replace', 10);

其中 old 是旧的字符串,new 是你要替换的文字。

参考自:http://wange.im/str-replace-in-wordpress.html