wp_print_scripts() WordPress Function

The wp_print_scripts function is a built-in function in WordPress that allows you to print scripts to the front-end of your website. This function is typically used to add JavaScript to your website.

wp_print_scripts( string|bool|array $handles = false ) #

Prints scripts in document head that are in the $handles queue.


Description

Called by admin-header.php and ‘wp_head’ hook. Since it is called by wp_head on every page load, the function does not instantiate the WP_Scripts object unless script names are explicitly passed. Makes use of already-instantiated $wp_scripts global if present. Use provided ‘wp_print_scripts’ hook to register/enqueue new scripts.

Top ↑

See also


Top ↑

Parameters

$handles

(string|bool|array)(Optional) Scripts to be printed. Default 'false'.

Default value: false


Top ↑

Return

(string[]) On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.


Top ↑

Source

File: wp-includes/functions.wp-scripts.php

function wp_print_scripts( $handles = false ) {
	global $wp_scripts;

	/**
	 * Fires before scripts in the $handles queue are printed.
	 *
	 * @since 2.1.0
	 */
	do_action( 'wp_print_scripts' );

	if ( '' === $handles ) { // For 'wp_head'.
		$handles = false;
	}

	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );

	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
		if ( ! $handles ) {
			return array(); // No need to instantiate if nothing is there.
		}
	}

	return wp_scripts()->do_items( $handles );
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.