get_template_directory_uri() returns http instead of https on SSL site get_template_directory_uri() returns http instead of https on SSL site wordpress wordpress

get_template_directory_uri() returns http instead of https on SSL site


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


Go into Settings -> General and check the Site URL.

It sounds like the problem you're having is this value is still HTTP, not HTTPS. Approach this change with caution. Make sure you have a working backup and a full understanding of why this URL needs to change as well as the impact it will have.

get_template_directory_uri() will automatically provide a HTTPS link when site URL is set correctly.