How can I enqueue protocol relative external (//ajax.googleapis.com/…) scripts?

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:

Read More
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&ver=3'></script>

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

Related posts

Leave a Reply

1 comment

  1. 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);
    }