wordpress一段代碼實現全站SSL

網絡上有非常多的各式各樣的WordPress開啟https訪問的方法,這裡我就分享最簡單的全站開啟SSL教程。

wordpress一段代碼實現全站SSL

把下面代碼放至正在使用的主題function.php文件內。

代碼

  1. //WordPress SSL at 2017/2/5 update

  2. add_filter('get_header', 'fanly_ssl');

  3. function fanly_ssl(){

  4. if( is_ssl() ){

  5. function fanly_ssl_main ($content){

  6. $siteurl = get_option('siteurl');

  7. $upload_dir = wp_upload_dir();

  8. $content = str_replace( 'http:'.strstr($siteurl, '//'), 'https:'.strstr($siteurl, '//'), $content);

  9. $content = str_replace( 'http:'.strstr($upload_dir['baseurl'], '//'), 'https:'.strstr($upload_dir['baseurl'], '//'), $content);

  10. return $content;

  11. }

  12. ob_start("fanly_ssl_main");

  13. }

  14. }

如果你的WordPress站點開啟了HTTPS,但在百度瀏覽器、獵豹瀏覽器等打開地址欄前未顯示綠色小鎖圖標或顯示的小鎖有"!",那麼說明你的網站加載了非SSL引入的資源,請把引入的外鏈本地化或把外鏈換成HTTPS鏈接。

相關推薦

推薦中...