wp_enqueue_script( string $handle, string $src = '', string[] $deps = array(), string|bool|null $ver = false, array|bool $args = array() )
Enqueues a script.
Description
Registers the script if $src provided (does NOT overwrite), and enqueues it.
See also
Parameters
- $handle
-
(Required) Name of the script. Should be unique.
- $src
-
(Optional) Full URL of the script, or path of the script relative to the WordPress root directory.<br>
Default value: ''
- $deps
-
(Optional) An array of registered script handles this script depends on.
Default value: array()
- $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.<br> If set to null, no version is added.
Default value: false
- $args
-
(Optional) An array of additional script loading strategies. <br> Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false.<br>
- 'strategy'
(string) Optional. If provided, may be either 'defer' or 'async'.<br> - 'in_footer'
(bool) Optional. Whether to print the script in the footer. Default 'false'.<br>
Default value: array()
- 'strategy'
Source
File: wp-includes/functions.wp-scripts.php
function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) {
$wp_scripts = wp_scripts();
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
if ( $src || $in_footer ) {
$_handle = explode( '?', $handle );
if ( $src ) {
$wp_scripts->add( $_handle[0], $src, $deps, $ver );
}
if ( $in_footer ) {
$wp_scripts->add_data( $_handle[0], 'group', 1 );
}
}
$wp_scripts->enqueue( $handle );
}
Changelog
| Version | Description |
|---|---|
| 6.3.0 | The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array. |
| 2.1.0 | Introduced. |