2

My theme contains a parallax header image. How can I change the URL of the header image so that it uses HTTPS? I want to do it manually.

Currently the URL is:

http://example.com/themes/abc/header.jpg

I want to change it to:

https://example.com/themes/abc/header.jpg

Plugins are not helping me on this specific file (they are converting others). Chrome tells me the header is being loaded by jquery.js. I have no idea how jQuery is doing this.

I believe editing functions.php can help, but how can I do it?

  • You can use str_replace to change http to https in a specific string. First you will need to find the code responsible for adding this image. – Robert hue Oct 24 '15 at 5:12
  • Its a css generated by theme(bg image). Right now i solved it by overriding the theme's css. – Cijo Oct 25 '15 at 9:12
  • Is there an another way. – Cijo Oct 25 '15 at 9:15
  • Depends how your website is working. Why don't you post the URL of website and which image you want to change. Let us have a look. – Robert hue Oct 25 '15 at 9:17
  • CSS of header image is added in header. How it is being added in header. Also I am not sure why are you going through all this trouble for 1 image. Your website is setup as non https website and Most of the links are also non https. So try setting up website with https link and I am sure these links will change to https automatically. – Robert hue Oct 25 '15 at 9:45
0

Have you considered Protocol Rewriting? The code below will convert all http: and https: to // for each script, link, base, and image. Place this in your functions.php:

add_action( 'plugins_loaded', 'wpse_232287_init' );

function wpse_232287_init() { // Initiate the function
    ob_start( 'wpse_232287_remove_http' );
}

function wpse_232287_remove_http( $buffer ) {
    // Check for a Content-Type header, only apply rewriting to "text/html" or undefined
    $headers = headers_list();
    $content_type = null;

    foreach ( $headers as $header ) {
        if (strpos( strtolower( $header ), 'content-type:' ) === 0 ) {
            $pieces = explode( ':', strtolower( $header ) );
            $content_type = trim( $pieces[1] );
            break;
        }
    }

    if ( is_null( $content_type ) || substr( $content_type, 0, 9 ) === 'text/html' ) { // Replace 'href'/'src' attributes within script/link/base/img tags with '//'
        $return = preg_replace( "/(<(script|link|base|img|form)([^>]*)(href|src|action)=[\"'])https?:\\/\\//i", "$1//", $buffer );
        if ( $return ) { // On regex error, skip overwriting content
            $buffer = $return;
        }
    }
    return $buffer;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.