I'm using a third party JS file. And they have both http and https version. My site have some pages loading in https while most of pages are in http.

Now my question is could I do something in header.php so if my page is in https it will load the https version JS, otherwise load the http version?

Thank you!

2 Answers 2


If you link to the JS file just using something like //examplesite.com/js/jsfile.js without the http:// or https:// the browser should automatically get the correct http or https version

  • 4
    This is the correct way to do it, in all web development, not just WordPress. Commented Jan 17, 2015 at 18:57

You can check if the site is SSL when enqueueing your JS files.

function theme_name_scripts() {
    if( is_ssl() ){
      # Running HTTPS
      wp_enqueue_script( 'https-js', get_template_directory_uri() . '/js/https.js );
      # Not HTTPS
      wp_enqueue_script( 'http-js', get_template_directory_uri() . '/js/http.js );

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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