queue_js_string — Add a JavaScript string to the current page.

Asset-related functions


queue_js_string($string, $options = array())

Add a JavaScript string to the current page.

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

  • $string (string) – JavaScript string to include.
  • $options (array) – An array of options.


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.


Use to add arbitrary javascript code to a page.

<?php queue_js_string("
      window.addEventListener('load', function() {
      }, false);
"); ?>