WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Javascript Reference

This page is marked as incomplete. You can help Codex by expanding it.

Introduction

This page documents the JavaScript APIs available to WordPress plugin developers, and how to use them.

This article assumes you have already read Writing a Plugin, which gives an overview (and many details) of how to develop a plugin, and that you already have a firm understanding of object-oriented JavaScript.

Locations

Most of WordPress's JavaScript files can be found in two locations.

Global JavaScript
The source scripts for use anywhere are located in js/_enqueues/wp/ and output in `wp-includes/js/` during the build process.
Admin JavaScript
The source scripts for use in admin are located in js/_enqueues/admin/ and output in `wp-admin/js/` during the build process.

Core Admin Libraries

  • wp (object) - The namespace object for nearly all WordPress scripts
  • wp.media - Handles the interactive media library

3rd Party Libraries

The following 3rd party libraries are included with WordPress:

php Support Functions

wp_register_script() 
Used to register a script with WordPress without enqueuing
wp_deregister_script() 
Used to de-register a script with WordPress without enqueuing
wp_enqueue_script() 
Used to add a script to WordPress's rendering queue
wp_dequeue_script() 
Used to remove a script from WordPress's rendering queue
wp_script_is() 
Determines the status of a script: whether it's been registered, enqueued, or printed/rendered.
wp_localize_script() 
Used to output PHP as JavaScript, typically so that JavaScript text can be localized.
wp_enqueue_media() 
Used to force all WordPress media-management assets to be loaded, generally used when you need to access the media scripts and libraries on screens where they are not automatically enqueued.