如果你想替换某些文章或评论中的文字,那么你将下面的代码添加到主题的 functions.php 即可:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/** * WordPress 快速替换文章/评论的某些文字内容 * http://www.wpdaxue.com/replace-text-of-content-or-comment.html */ function wpdaxue_replace_text($text){ $replace = array( // '原始文字' => '替换为这些' '七支剑' => '<a href="http://www.speedfly.cn" target="_blank">七支剑</a>', '张家港网云论坛' => '<a href="http://www.zjg888.com/">张家港网云论坛</a>' ); $text = str_replace(array_keys($replace), $replace, $text); return $text; } add_filter('the_content', 'wpdaxue_replace_text'); //正文 add_filter('the_excerpt', 'wpdaxue_replace_text'); //摘要 add_filter('comment_text', 'wpdaxue_replace_text'); //评论 |
这个其实就是一个转换 实际内容还是存在数据库的
如果想永久替换数据库内容 可以试试以下SQL语句
1 |
UPDATE wp_posts SET post_content = REPLACE( post_content, '原内容', '新内容' ); |
数据库操作之前请先备份数据库 防止意外发生