wordpress 修改http成https

1.后台登录样式乱?发现wordpress会根据is_ssl来决定走http/https,我想用https,所以直接给个true.


#vi wp-includes/load.php
function is_ssl() {
if ( isset( $_SERVER['HTTPS'] ) ) {
if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
return true;
}
if ( '1' == $_SERVER['HTTPS'] ) {
return true;
}
} elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
return true;
}
# return false;
return true; ##whatever let it ture.
}

 

2.前台部分,在模板里修改下functions.php增加一个替换http->https的方法
#vi wp-content/themes/twentyseventeen/functions.php

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, '//'), strstr($siteurl, '//'), $content);
$content = str_replace( 'http:'.strstr($upload_dir['baseurl'], '//'), strstr($upload_dir['baseurl'], '//'), $content);
return $content;
}
ob_start("change_ssl_main");
}
}
add_filter('get_header', 'change_ssl');

3.能想到的地方都修改一下,【设置】-【常规】里修改成https

4.之前发布的文章:

update wp_posts set post_content = replace(post_content, '//www.lijiuyang.com','https://www.lijiuyang.com');