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

cera cera

可有两种方法实现替换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 是你要替换的文字。

來源:https://bynss.com/2018/865.html

cera cloudiplc tengxunyun

相关推荐

mjjping.com cera cera cloudiplc