wp_register_script

Register a new script.

Description

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

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

Parameters (5)

0. $handle (string)
Name of the script. Should be unique.
1. $src (string)
Full URL of the script, or path of the script relative to the WordPress root directory.
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_register_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. $src = ''; 
  9.  
  10. // Optional. An array of registered script handles this script depends on. Default empty array. 
  11. $deps = array(); 
  12. $ver = false; 
  13.  
  14. // Optional. Whether to enqueue the script before instead of in the . 
  15. // Default 'false'. 
  16. $in_footer = false; 
  17.  
  18. // NOTICE! Understand what this does before running. 
  19. $result = wp_register_script($handle, $src, $deps, $ver, $in_footer); 
  20.  

Defined (1)

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

/wp-includes/functions.wp-scripts.php  
  1. function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 
  2. $wp_scripts =wp_scripts); 
  3.  
  4. $registered = $wp_scripts->add( $handle, $src, $deps, $ver ); 
  5. if ( $in_footer ) { 
  6. $wp_scripts->add_data( $handle, 'group', 1 ); 
  7.  
  8. return $registered;