Wordpress get_template_directory_uri () returns http instead of https

We recently applied an SSL certificate on our website and want our entire url to have https: // protocol.

As soon as we moved our site to https: //, our website broke down because there were few resources that still pointed to http: //. After some research time, I saw that get_template_directory_uri () always returns http: // even through our wp_home, wp_site_url is set using https: //

Is there another place where we need to change the url as we are using a child theme and this function gets the parent directory of the theme.

Thank you Raju Visvas

+6
source share
5 answers

Check the value of $_SERVER['HTTPS'] . This should be set to on or 1 . If it has a different value during installation, this function will output http, not https.

See: https://core.trac.wordpress.org/browser/tags/4.5.3/src/wp-includes/functions.php#L4025

+6
source

view link notes https://codex.wordpress.org/Function_Reference/is_ssl

 if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS'] = 'on'; 
+2
source

Following this comment, the initiator added:

in my case, we used the Load Balancer server and the SSL certificate was installed on the load balancer

Reply from @pbond scratched the surface to the root cause of the problem. The WordPress function is_ssl() checks $ _SERVER ['HTTPS'] and $ _SERVER ['SERVER_PORT'] to check if the current page is accessible via https, but the load balancer most likely requests your content on a port other than SSL 80.

A good solution for this is to use the X-Forwareded-Proto HTTP header to determine which protocol the client actually uses on the other side of load balancing.

With Apache 2.2, you can add this to your configuration:

 <IfModule mod_setenvif.c> SetEnvIf X-Forwarded-Proto "^https$" HTTPS </IfModule> 

Another possible fix (mentioned by @Roberto Poblete but not explained) is to add this to wp-config.php

 if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS'] = 'on'; 

I have it thanks for sending me directly

+1
source

Have you tried to force content delivery via https with a modified .htaccess file?

below the snippet I'm using:

 #Force HTTPS RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
0
source

Please use the following:

 get_stylesheet_directory_uri(); 

this will be the web address (starting with http: // or https: // for SSL). Thus, it is most suitably used for links, links to additional style sheets, or perhaps most often images.

https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

-2
source

All Articles