Codex

Function Reference/wp enqueue script

Contents

Description

A safe way of adding javascripts to a WordPress generated page.

Usage

<?php wp_enqueue_script'handle''src''deps''ver'); ?>

Example

Usage

Load the scriptaculous script:

<?php wp_enqueue_script('scriptaculous'); ?>

Add and load a new script that depends on scriptaculous (this will also cause it to load scriptaculous into the page as well):

<?php wp_enqueue_script('newscript',
'/wp-content/plugins/someplugin/js/newscript.js',
array('scriptaculous'),
'1.0' ); ?>


Parameters

handle 
(string) Name of the script. Lowercase string.
src
(string) (Optional) Path to the script from the root directory of WordPress. Example: "/wp-includes/js/scriptaculous/scriptaculous.js". This parameter is only required when WordPress does not already know about this script. Defaults to false.
deps
(array) (Optional) Array of handles of any script that this script depends on; scripts that must be loaded before this script. false if there are no dependencies. This parameter is only required when WordPress does not already know about this script. Defaults to false.
ver 
(string) (Optional) String specifying the script version number, if it has one. Defaults to false. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the script.

Default scripts included with WordPress:

Script Name Handle
Docking Boxes dbx
Fade Anything Technique fat
Simple AJAX Code-Kit sack
QuickTags quicktags
ColorPicker colorpicker
Tiny MCE tiny_mce
WordPress Tiny MCE wp_tiny_mce
Prototype Framework prototype
Autosave autosave
WordPress AJAX wp-ajax
List Manipulation listman
Scriptaculous Root scriptaculous-root
Scriptaculous Builder scriptaculous-builder
Scriptaculous Drag & Drop scriptaculous-dragdrop
Scriptaculous Effects scriptaculous-effects
Scriptaculous Slider scriptaculous-slider
Scriptaculous Controls scriptaculous-controls
Scriptaculous scriptaculous
Image Cropper cropper
SWFUpload swfpload
jQuery jquery
jQuery Suggest suggest
ThickBox thickbox

Resources

This article is marked as in need of editing. You can help Codex by editing it.