Use https for img src

WordPress checks the return value of is_ssl() before creating URLs using get_bloginfo(). If the function returns true, it creates https URLs. If it returns false, it creates http URLs.

From the WordPress source …

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;
}

So … if the request was made over https or if the request came in over port 443, then get_bloginfo() will return an https:// URL. In reality, if you’re forcing https anyway, you should force all requests to port 80 (http) over to port 443 (https) … but that’s a server configuration issue, not a WordPress issue.

Alternatively, you could hook into a filter and replace http with https …

Just use:

function replace_http( $original ) {
    // use preg_replace() to replace http:// with https://
    $output = preg_replace( "^http:", "https:", $original );
    return $output;
}

add_filter( 'template_url', 'replace_http' );

Leave a Comment