Protocol neutral URLS with wp_enqueue_script (SSL issues)?

You can’t — URLs must have a protocol for WordPress to enqueue them. What you can do, though, is detect which protocol to use and then use that.

$protocol = is_ssl() ? 'https' : 'http';
$url = "$protocol://example.com/resource";

But for enqueuing scripts from your theme, you should use get_template_directory_uri() or get_stylesheet_directory_uri() which already handle SSL:

wp_enqueue_script('name', get_stylesheet_directory_uri() . '/js/name.pack.js');

Leave a Comment

error code: 523