I know the topic has been already discussed, but it seems no solution was found. This is my case: I have a wordpress site which now has SSL. However, in the theme resources are added as follows:
wp_enqueue_script( 'spectrumwp-conditional', get_template_directory_uri() . '/js/vendor/conditional.js', array('jquery'), null, true);
but get_template_directory_uri() returns the url with http not https.
Can you help me to solve this?
Edit: I added this to my wp-config.php file
$_SERVER['HTTPS']='on';
Links to resources are shown with https:// but instead of, for example
https://www.exaple.com/wp-content/plugins/...
I have
https://www.example.com/plugins/LayerSlider/...
e.g. wp-content folder is missing
Final update:
uncommenting
define('FORCE_SSL_ADMIN', true);
and adding
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
{ $_SERVER['HTTPS']='on'; }
just before the line
/* That's all, stop editing! Happy blogging. */
fixed the problem! Only, I recommend $_SERVER['HTTP_X_FORWARDED_PROTO'] is not used, as it may not be accurate enough.
Solved!
You need to use is_ssl() to check if the site is running https:// or http://
Here is the hook to check and redirect :
function check_if_https() {
if ( !is_ssl() ) {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
add_action ( 'template_redirect', 'check_if_https', 1 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With