queue_js_string — Add a JavaScript string to the current page.

Asset-related functions

Summary

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.

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

Usage

Examples

Use to add arbitrary javascript code to a page. Combine with head_js() to add to the page head inside <script></script> tags.

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

<?php head_js(); ?>