Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

According to the Codex, wp_enqueue_script supports protocol relative, or protocol agnostic external links: "Remote assets can be specified with a protocol-agnostic URL, i.e. '//otherdomain.com/js/theirscript.js'."

But I'm not seeing it:

wp_enqueue_script('google-maps', '//maps.googleapis.com/maps/api/js?&sensor=false', array(), '3', true);

Output:

<script type='text/javascript' src='http://localhost:25898//maps.googleapis.com/maps/api/js?sensor=false&#038;ver=3'></script>

Notice that the protocol relative URL is appended to the site URL.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The code you posted works fine and results in this in the HTML output:

<script type='text/javascript' src='//maps.googleapis.com/maps/api/js?sensor=false&#038;ver=3'></script>

Tested on WordPress 3.5 with this code snippet:

add_action('wp_enqueue_scripts', 'test');
function test() {
  wp_enqueue_script('google-maps', '//maps.googleapis.com/maps/api/js?&sensor=false', array(), '3', true);
}
share|improve this answer
    
Do you know it this is new in WordPress 3.5? –  michielvoo Jan 25 '13 at 13:12
    
Protocol-relative URLs was added 7 months ago: core.trac.wordpress.org/ticket/16560 –  Otto Jan 25 '13 at 16:25
    
Ok, so it's not the version of WordPress that I'm using. So what could cause the difference in behaviour? –  michielvoo Jan 28 '13 at 9:59
1  
Well, that code was added 7 months ago, but if you look at the ticket, it has a 3.5 milestone, so yes it's probably new behavior to 3.5. –  Otto Jan 28 '13 at 22:13
    
Oh right, I was looking at the 'Version' field which was set to 3.1, but that's the version of WordPress at the time the ticket was created. –  michielvoo Jan 29 '13 at 12:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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