wp_register_script

Advertisement

Summery Summery

Register a new script.

Syntax Syntax

wp_register_script( string $handle, string|bool $src, string[] $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

Description Description

Registers a script to be enqueued later using the wp_enqueue_script() function.

Parameters Parameters

$handle

(string) (Required) Name of the script. Should be unique.

$src

(string|bool) (Required) Full URL of the script, or path of the script relative to the WordPress root directory. If source is set to false, script is an alias of other scripts it depends on.

$deps

(string[]) (Optional) An array of registered script handles this script depends on.

Default value: array()

$ver

(string|bool|null) (Optional) String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.

Default value: false

$in_footer

(bool) (Optional) Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.

Default value: false

Return Return

(bool) Whether the script has been registered. True on success, false on failure.

Source Source

File: wp-includes/functions.wp-scripts.php

 *
 * @see WP_Dependencies::add()
 * @see WP_Dependencies::add_data()
 *
 * @since 2.1.0
 * @since 4.3.0 A return value was added.
 *
 * @param string           $handle    Name of the script. Should be unique.
 * @param string|bool      $src       Full URL of the script, or path of the script relative to the WordPress root directory.
 *                                    If source is set to false, script is an alias of other scripts it depends on.
 * @param string[]         $deps      Optional. An array of registered script handles this script depends on. Default empty array.

Advertisement

Changelog Changelog

Changelog
Version Description
4.3.0 A return value was added.
2.1.0 Introduced.

See also See also

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.