wordpress開啓https

        域名配置好https之後,我們需要修改當前wordpress的主題下的function.php文件,如wp-content/themes/dux/functions.php,dux就是我們現在正在使用的主題。在此文件的最下方加上如下代碼:

//http to https

function change_ssl(){
    if( is_ssl() ){
        function change_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['baseurl'], '//'), $content);
            return $content;
        }
        ob_start('change_ssl_main');
    }
}
add_filter('get_header', 'change_ssl');

再測試一下,完美的綠鎖!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章