WordPress安装SSL之后,前台样式会乱掉。这时候需要你在数据库wp_options表里把原本的http字段加上https。文章源自原紫番博客-https://www.yuanzifan.com/54156.html
随后打开对应主题的functions.php。把下面的代码加在最后。文章源自原紫番博客-https://www.yuanzifan.com/54156.html
- // wordpress强制跳转https后,JS/CSS不加载的解决方案
- add_filter('script_loader_src', 'agnostic_script_loader_src', 20,2);
- function agnostic_script_loader_src($src, $handle) {
- return preg_replace('/^(http|https):/', '', $src);
- }
- add_filter('style_loader_src', 'agnostic_style_loader_src', 20,2);
- function agnostic_style_loader_src($src, $handle) {
- return preg_replace('/^(http|https):/', '', $src);
- }
这时前台的样式已经恢复了。但是某些情况下后台无法登录,登录就报错。这是因为你后台没有开启SSL登录。把面的代码加在config.php的最上面,(注意 不是第一排,而是@package wordpress)下面,注释符号后面的第一排。如果加在最后是不行的,因为加载最后,setting和phploading都已经加载了,会影响生效。文章源自原紫番博客-https://www.yuanzifan.com/54156.html
- * @package WordPress
- */
- $_SERVER['HTTPS'] = 'on';
- define('FORCE_SSL_LOGIN', true);
- define('FORCE_SSL_ADMIN', true);
站长微信
扫码添加(注明来意)

Yuanzifan99
原梓番博客公众号
博客内容精选

原梓番博客
评论