Scripts Handler

The scripts handler exposes the following public methods:

  • register_public_script for adding a script to the internal frontend registration queue

  • deregister_public_script for removing a script from the internal frontend registration queue

  • enqueue_public_script for adding a script to the internal frontend enqueueing queue

  • dequeue_public_script for removing a script from the internal frontend enqueueing queue

  • register_admin_script for adding a script to the internal admin-side registration queue

  • deregister_admin_script for removing a script from the internal admin-side registration queue

  • enqueue_admin_script for adding a script to the internal admin-side enqueueing queue

  • dequeue_admin_script for removing a script from the internal admin-side enqueueing queue

  • add_inline_script for registering a JS string to be outputted before or after another enqueued file

  • localize_script for including a JS object variable to be outputted before another enqueued file is

The methods follow almost 1-to-1 the WP scripts API, in particular the wp_register_script function, the wp_enqueue_script function, the wp_add_inline_script function, and the wp_localize_script function.

The register_admin_script and enqueue_admin_script methods accept a specialized argument $hook_suffixes. By default it's null, but it can be set to an array to conditionally register/enqueue the scripts only when the global variable $hook_suffix is set to one of the values.

As mentioned on the Assets Service page, the handler will automatically attempt to register/enqueue the minified version of your script (if it exists in the same folder and has the .min.js extension) and will attempt to set the file version to the result of the PHP filemtime function.

For assets being loaded from an external URL, the $fallback_version argument will be used by default instead of trying to call filmemtime on the script.

Last updated