1

All css and js load url http not https after apply ssl in my wordpress site. home page load proper but inner page not load proper because css and js path use http.

url use https.

2 Answers 2

2

Add this to your wp-config.php

// Work out if we are using https
$isSecure = false;
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
    $isSecure = true;
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
    $isSecure = true;
}
$REQUEST_PROTOCOL = $isSecure ? 'https://' : 'http://';
define( 'WP_CONTENT_URL', $REQUEST_PROTOCOL.$_SERVER['HTTP_HOST'] . '/wp-content');
define( 'WP_HOME', $REQUEST_PROTOCOL.$_SERVER['HTTP_HOST'] );

And make sure all your CSS and JS is using the enque functions: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts

Sign up to request clarification or add additional context in comments.

2 Comments

Hi. I want to allow url https of all pages in wordpress site.
Make sure that your wordpress address and site address are both set to https. Check settings > general to check this.
1

If the web server is behind a proxy service, like squid or cloudflare,

// BEGIN NEW TWO LINES
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && ( 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
    return true;
    // END NEW TWO LINES

you can add these two lines inside of "is_ssl()" function in "wp-includes/load.php" file.

Finally you will get this:

/**
 * Determines if SSL is used.
 *
 * @since 2.6.0
 * @since 4.6.0 Moved from functions.php to load.php.
 *
 * @return bool True if SSL, otherwise false.
 */
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;
    // BEGIN NEW TWO LINES
    } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && ( 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) { // <== NEW
        return true;
        // END NEW TWO LINES
    }
    return false;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.