WordPress改写所有http链接为https协议|全站SSL

文章目录[隐藏]

前言

自己的多个网站都使用了百度的CDN,一级域名下只能设置一种回源模式:要么全程ssl要么半程ssl。由于部分服务的源站没办法使用ssl加密,所以只能选择半程。
但是半程意味着http回源,导致WordPress给出的所有链接均为http,于是报错....

解决方案

后台设置里面,依次打开【外观】》【主题编辑器】》【模板函数 (functions.php)】
在末尾添加如下代码:



/** 替换链接为https **/

function rewrite_to_https($content){

    if( is_ssl() ){

        $content = str_replace('http://', 'https://', $content);

    }

    return $content;

}

add_filter('the_content', 'rewrite_to_https');

保存即可。


This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/1077.html
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy