WordPress at a glance

wp_register_script() WP 1.0

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 4.3.0 A return value was added.

No Hooks.

Return

true/false. Whether the script has been registered. True on success, false on failure.

Usage

wp_register_script( $handle, $src, $deps, $ver, $in_footer );
$handle(string) (required)
Name of the script. Should be unique.
$src(string/true/false) (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(array)
An array of registered script handles this script depends on.
Default: empty array
$ver(string/true/false/null)
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: false
$in_footer(true/false)
Whether to enqueue the script before </body> instead of in the <head>.
Default: 'false'

Code of wp register script: wp-includes/functions.wp-scripts.php WP 5.2.2

<?php
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;
}

Related Functions

From tag: script

More from category: Scripts and Styles

No comments
    Hello, !     Log In . Register