【wordpress代码】一段代码实现全站SSL

西瓜君在这儿分享最简单的全站开启SSL教程。把下面代码放至正在使用的主题function.php文件内就可以了

代码

//WordPress SSL
add_filter('get_header', 'fanly_ssl');
function fanly_ssl(){
if( is_ssl() ){
function fanly_ssl_main ($content){
$siteurl = get_option('siteurl');
$upload_dir = wp_upload_dir();
$content = str_replace( 'http:'.strstr($siteurl, '//'), 'https:'.strstr($siteurl, '//'), $content);
$content = str_replace( 'http:'.strstr($upload_dir['baseurl'], '//'), 'https:'.strstr($upload_dir['bas
eurl'], '//'), $content);
return $content;
}
ob_start("fanly_ssl_main");
}
}

提示

如果你的WordPress站点开启了HTTPS,但在百度浏览器、猎豹浏览器等打开地址栏前未显示绿色小锁图标或显示的小锁有”!”,那么说明你的网站加载了非SSL引入的资源,请把引入的外链本地化或把外链换成HTTPS链接。

发表评论