如何在wordpress中替换图片的旧域名

如果你更换了wordpress站点的域名后,需要更新文章中图片的域名地址。可通过如下方式进行:

在主题的function.php文件中增加以下代码:

function replace_text_wps($text) {
$replace = array(
‘http://旧域名.com’ => ‘http://新域名.com’,
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter(‘the_content’, ‘replace_text_wps’);
add_filter(‘the_excerpt’, ‘replace_text_wps’);

给TA打赏
共{{data.count}}人
人已打赏
WordPress未分类

一款自动切换简体中文与繁体中文的WordPress插件

2025-9-1 17:51:47

Mac应用Windows应用

快来解锁最新版 Typora,会员首单立减后仅需 84 元!

2025-9-1 17:51:47

个人中心
今日签到
有新私信 私信列表
搜索