In this WordPress function to register a script wp_register_script can be used, to load external scripts, the follow format:
wp_register_script('my_jQuery', '//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js');
As appears in documentation the second parameter can begins with “//” to leave WordPress specify the protocol:
Remote assets can be specified with a protocol-agnostic URL, i.e.
‘//otherdomain.com/js/theirscript.js’. Default: None
For WordPress 3.5.1 works fine, but for WordPress 3.4.2 doesn’t.
Two questions:
1- From which WordPress version can be used the second parameter with “//”?
2- For WordPress versions that doesn’t support this format “//”, which is the recommended way of call the external resource? Should I ask for WordPress page protocol and use accordingly it?
This was discussed in core Ticket #16560:
The ticket was closed and set to fixed eight months ago, but only implemented in version 3.5.
For cases where you need to manually check the protocol, the function
is_ssl()
is used:Although I do not know which versions of WordPress support the protocol-agnostic URL, I can answer your second question. The purpose of protocol-agnostic URLs is to automatically use either an SSL connection or a regular connection when loading resources based on what is currently being used to load the page. Whether or not you are using an SSL connection on your website, if you want to support older versions of WordPress, then I would use
https://
instead of//
when possible. Please note, this will only work for external scripts that support an SSL connection, like Google’s hosted scripts. If the resource you are loading does not support SSL, then the choice is clear, just usehttp://
instead of//