wp_register_script

The timeline below displays how wordpress function wp_register_script has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Registers a new script.
 *
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
 *
 * @see WP_Dependencies::add()
 * @see WP_Dependencies::add_data()
 *
 * @since 2.1.0
 * @since 4.3.0 A return value was added.
 * @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array.
 *
 * @param string           $handle    Name of the script. Should be unique.
 * @param string|false     $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.
 * @param string|bool|null $ver       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.
 * @param array|bool       $args     {
 *     Optional. An array of additional script loading strategies. Default empty array.
 *     Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.
 *
 *     @type string    $strategy     Optional. If provided, may be either 'defer' or 'async'.
 *     @type bool      $in_footer    Optional. Whether to print the script in the footer. Default 'false'.
 * }
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $args = array())
{
    if (!is_array($args)) {
        $args = array('in_footer' => (bool) $args);
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__, $handle);
    $wp_scripts = wp_scripts();
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if (!empty($args['in_footer'])) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    if (!empty($args['strategy'])) {
        $wp_scripts->add_data($handle, 'strategy', $args['strategy']);
    }
    return $registered;
}

WordPress Version: 6.3

/**
 * Registers a new script.
 *
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
 *
 * @see WP_Dependencies::add()
 * @see WP_Dependencies::add_data()
 *
 * @since 2.1.0
 * @since 4.3.0 A return value was added.
 * @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array.
 *
 * @param string           $handle    Name of the script. Should be unique.
 * @param string|false     $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.
 * @param string|bool|null $ver       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.
 * @param array|bool       $args     {
 *      Optional. An array of additional script loading strategies. Default empty array.
 *      Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.
 *
 *      @type string    $strategy     Optional. If provided, may be either 'defer' or 'async'.
 *      @type bool      $in_footer    Optional. Whether to print the script in the footer. Default 'false'.
 * }
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $args = array())
{
    if (!is_array($args)) {
        $args = array('in_footer' => (bool) $args);
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__, $handle);
    $wp_scripts = wp_scripts();
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if (!empty($args['in_footer'])) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    if (!empty($args['strategy'])) {
        $wp_scripts->add_data($handle, 'strategy', $args['strategy']);
    }
    return $registered;
}

WordPress Version: 6.2

/**
 * Registers a new script.
 *
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
 *
 * @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|false     $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.
 * @param string|bool|null $ver       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.
 * @param bool             $in_footer Optional. Whether to enqueue the script before `</body>` instead of in the `<head>`.
 *                                    Default 'false'.
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__, $handle);
    $wp_scripts = wp_scripts();
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    return $registered;
}

WordPress Version: 6.1

/**
 * Register a new script.
 *
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
 *
 * @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|false     $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.
 * @param string|bool|null $ver       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.
 * @param bool             $in_footer Optional. Whether to enqueue the script before `</body>` instead of in the `<head>`.
 *                                    Default 'false'.
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__, $handle);
    $wp_scripts = wp_scripts();
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    return $registered;
}

WordPress Version: 5.5

/**
 * Register a new script.
 *
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
 *
 * @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.
 * @param string|bool|null $ver       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.
 * @param bool             $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
 *                                    Default 'false'.
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__, $handle);
    $wp_scripts = wp_scripts();
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    return $registered;
}

WordPress Version: 5.4

/**
 * Register a new script.
 *
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
 *
 * @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.
 * @param string|bool|null $ver       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.
 * @param bool             $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
 *                                    Default 'false'.
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    $wp_scripts = wp_scripts();
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    return $registered;
}

WordPress Version: 5.1

/**
 * Register a new script.
 *
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
 *
 * @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 array            $deps      Optional. An array of registered script handles this script depends on. Default empty array.
 * @param string|bool|null $ver       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.
 * @param bool             $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
 *                                    Default 'false'.
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    $wp_scripts = wp_scripts();
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    return $registered;
}

WordPress Version: 4.5

/**
 * Register a new script.
 *
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
 *
 * @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           $src       Full URL of the script, or path of the script relative to the WordPress root directory.
 * @param array            $deps      Optional. An array of registered script handles this script depends on. Default empty array.
 * @param string|bool|null $ver       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.
 * @param bool             $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
 *                                    Default 'false'.
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    $wp_scripts = wp_scripts();
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    return $registered;
}

WordPress Version: 4.3

/**
 * Register a new script.
 *
 * Registers a script to be linked later using the wp_enqueue_script() function.
 *
 * @see WP_Dependencies::add(), WP_Dependencies::add_data()
 *
 * @since 2.6.0
 * @since 4.3.0 A return value was added.
 *
 * @param string      $handle    Name of the script. Should be unique.
 * @param string      $src       Path to the script from the WordPress root directory. Example: '/js/myscript.js'.
 * @param array       $deps      Optional. An array of registered script handles this script depends on. Set to false if there
 *                               are no dependencies. Default empty array.
 * @param string|bool $ver       Optional. String specifying script version number, if it has one, which is concatenated
 *                               to end of path as a query string. If no version is specified or set to false, a version
 *                               number is automatically added equal to current installed WordPress version.
 *                               If set to null, no version is added. Default 'false'. Accepts 'false', 'null', or 'string'.
 * @param bool        $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
 *                               Default 'false'. Accepts 'false' or 'true'.
 * @return bool Whether the script has been registered. True on success, false on failure.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    $wp_scripts = wp_scripts();
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    $registered = $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
    return $registered;
}

WordPress Version: 4.2

/**
 * Register a new script.
 *
 * Registers a script to be linked later using the wp_enqueue_script() function.
 *
 * @see WP_Dependencies::add(), WP_Dependencies::add_data()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.6.0
 *
 * @param string      $handle    Name of the script. Should be unique.
 * @param string      $src       Path to the script from the WordPress root directory. Example: '/js/myscript.js'.
 * @param array       $deps      Optional. An array of registered script handles this script depends on. Set to false if there
 *                               are no dependencies. Default empty array.
 * @param string|bool $ver       Optional. String specifying script version number, if it has one, which is concatenated
 *                               to end of path as a query string. If no version is specified or set to false, a version
 *                               number is automatically added equal to current installed WordPress version.
 *                               If set to null, no version is added. Default 'false'. Accepts 'false', 'null', or 'string'.
 * @param bool        $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
 *                               Default 'false'. Accepts 'false' or 'true'.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    $wp_scripts = wp_scripts();
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
}

WordPress Version: 3.7

/**
 * Register a new script.
 *
 * Registers a script to be linked later using the wp_enqueue_script() function.
 *
 * @see WP_Dependencies::add(), WP_Dependencies::add_data()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.6.0
 *
 * @param string      $handle    Name of the script. Should be unique.
 * @param string      $src       Path to the script from the WordPress root directory. Example: '/js/myscript.js'.
 * @param array       $deps      Optional. An array of registered script handles this script depends on. Set to false if there
 *                               are no dependencies. Default empty array.
 * @param string|bool $ver       Optional. String specifying script version number, if it has one, which is concatenated
 *                               to end of path as a query string. If no version is specified or set to false, a version
 *                               number is automatically added equal to current installed WordPress version.
 *                               If set to null, no version is added. Default 'false'. Accepts 'false', 'null', or 'string'.
 * @param bool        $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
 *                               Default 'false'. Accepts 'false' or 'true'.
 */
function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
    global $wp_scripts;
    if (!is_a($wp_scripts, 'WP_Scripts')) {
        if (!did_action('init')) {
            _doing_it_wrong(__FUNCTION__, sprintf(__('Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.'), '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>'), '3.3');
        }
        $wp_scripts = new WP_Scripts();
    }
    $wp_scripts->add($handle, $src, $deps, $ver);
    if ($in_footer) {
        $wp_scripts->add_data($handle, 'group', 1);
    }
}