您可以通过以下步骤将外链图片修改为所需的格式:
外链图片修改
- 登录WordPress后台,进入“外观”-“编辑器”,找到functions.php文件。
- 在functions.php文件的末尾添加以下代码:
function replace_image_url($content) {
$content = str_replace(array('http://xxx.xyz', 'https://xxx.xyz'), 'https://i1.wp.com/xxx.xyz', $content);
return $content;
}
add_filter('the_content', 'replace_image_url');
- 点击“更新文件”保存修改。
特色图片修改
您可以在上面的代码中再添加以下代码,来实现特色图像的修改:
function replace_featured_image_url($html, $post_id, $post_image_id) {
$html = str_replace('http://xxx.xyz', 'https://i1.wp.com/xxx.xyz', $html);
$html = str_replace('https://xxx.xyz', 'https://i1.wp.com/xxx.xyz', $html);
return $html;
}
add_filter('post_thumbnail_html', 'replace_featured_image_url', 10, 3);
这段代码会在文章的特色图像中自动将"http://xxx.xyz"和"https://xxxx.xyz"替换为"https://i1.wp.com/xxx.xyz",从而实现特色图像的修改。同样请注意备份文件,以防出现不可预料的错误。