wp_enqueue_script

Enqueue a script.

Description

wp_enqueue_script( (string) $handle, (string) $src = '', (array) $deps = array(), (constant) $ver = false, (bool) $in_footer = false ); 

Registers the script if $src provided (does NOT overwrite), and enqueues it.

Parameters (5)

0. $handle (string)
Name of the script. Should be unique.
1. $src — Optional. (string) => ''
Full URL of the script, or path of the script relative to the WordPress root directory. Default empty.
2. $deps — Optional. (array) => array()
An array of registered script handles this script depends on. Default empty array.
3. $ver — Optional. (constant) => false
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.
4. $in_footer — Optional. (bool) => false
Whether to enqueue the script before instead of in the. Default false..

Usage

  1. if ( !function_exists( 'wp_enqueue_script' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.wp-scripts.php'; 
  3.  
  4. // Name of the script. Should be unique. 
  5. $handle = ''; 
  6.  
  7. // Full URL of the script, or path of the script relative to the WordPress root directory. 
  8. // Default empty. 
  9. $src = ''; 
  10.  
  11. // Optional. An array of registered script handles this script depends on. Default empty array. 
  12. $deps = array(); 
  13. $ver = false; 
  14.  
  15. // Optional. Whether to enqueue the script before instead of in the . 
  16. // Default 'false'. 
  17. $in_footer = false; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = wp_enqueue_script($handle, $src, $deps, $ver, $in_footer); 
  21.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.wp-scripts.php  
  1. function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) { 
  2. $wp_scripts =wp_scripts); 
  3.  
  4.  
  5.  
  6. if ( $src || $in_footer ) { 
  7. $_handle = explode( '?', $handle ); 
  8.  
  9. if ( $src ) { 
  10. $wp_scripts->add( $_handle[0], $src, $deps, $ver ); 
  11.  
  12. if ( $in_footer ) { 
  13. $wp_scripts->add_data( $_handle[0], 'group', 1 ); 
  14.  
  15. $wp_scripts->enqueue( $handle );