前言
有时候给wordpress网站加上https后,却发现有的附图不是https,因此没有https小绿标。
用了这段代码,你就能强身健体,你就能把(所有)不是https的图片,转换为Https的链接。
wordpress图片https代码
将以下代码复制到主题目录下的functions.php,选择合适的位置插♂入,就行了。(别问我functions.php在哪编辑,我!不!知!道!(理直气壮.jpg))
注意把代码中的www.xjh.me改为你自己网站的域名
function replacehttp($content){
if( is_ssl() ){
$domain='www.xjh.me';
$content = str_replace('http://'.$domain.'/wp-content/uploads', 'https://'.$domain.'/wp-content/uploads', $content);
}
return $content;
}
add_filter('the_content', 'replacehttp');
