queue_js_url — Add a JavaScript file to the current page by URL.

Asset-related functions

Summary

queue_js_url($url, $options = array())

Add a JavaScript file to the current page by URL.

The script link will appear in the head element. This needs to be called either before head() or in a plugin_header hook.

Parameters:
  • $url
  • $options (array) – An array of options.

Usage

head_js actually outputs the scripts. All themes should already call head_js themselves, so you can just use the queue functions.

If writing a theme, queue_js_* functions must be called before the call to head_js. If writing a plugin, you make these calls within the admin_head or public_head hooks.

The $options array is passed as the $attrs parameter to the Zend Framework headScript helper. This can be used to set some attributes on the <script> tag as well as to enable some specific functionality of the ZF helper like IE conditional comments.

Examples

Use to load external javascript files, such as the jquery library.

<?php queue_js_url('//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'); ?>