queue_js_file — Add a local JavaScript file or files to the current page.

Asset-related functions

Summary

queue_js_file($file, $dir = 'javascripts', $options = array())

Add a local JavaScript file or files to the current page.

All scripts will be included in the page’s head. This needs to be called either before head(), or in a plugin_header hook.

Parameters:
  • $file (string|array) – File to use, if an array is passed, each array member will be treated like a file.
  • $dir (string) – Directory to search for the file. Keeping the default is recommended.
  • $options (array) – An array of options.

Usage

Examples

Use with head_js to include the links to the javascript files in the page head.

Load one javascript file from the default ‘javascripts’ folder within the theme directory:

<?php queue_js_file('my_js_file'); ?>

<?php head_js(); ?>

Load two javascript files from the default ‘javascripts’ folder:

<?php queue_js_file(array('my_js_file', 'another_js_file')); ?>

<?php head_js(); ?>

Load one javascript file from the default ‘javascripts’ folder with a conditional statement:

<?php queue_js_file('my_js_file', 'javascripts', array('conditional' => '(gte IE 6)&(lte IE 8)')); ?>

<?php head_js(); ?>