WP_Dependencies::enqueue() WordPress Method

The WP_Dependencies::enqueue() method is used to enqueue a script or style. Dependencies are handles for registered scripts and styles. Enqueued dependencies are not necessarily loaded in the order they are enqueued.

WP_Dependencies::enqueue( string|string[] $handles ) #

Queue an item or items.


Description

Decodes handles and arguments, then queues handles and stores arguments in the class property $args. For example in extending classes, $args is appended to the item url as a query string. Note $args is NOT the $args property of items in the $registered array.


Top ↑

Parameters

$handles

(string|string[])(Required)Item handle (string) or item handles (array of strings).


Top ↑

Source

File: wp-includes/class.wp-dependencies.php

	public function enqueue( $handles ) {
		foreach ( (array) $handles as $handle ) {
			$handle = explode( '?', $handle );

			if ( ! in_array( $handle[0], $this->queue, true ) && isset( $this->registered[ $handle[0] ] ) ) {
				$this->queue[] = $handle[0];

				// Reset all dependencies so they must be recalculated in recurse_deps().
				$this->all_queued_deps = null;

				if ( isset( $handle[1] ) ) {
					$this->args[ $handle[0] ] = $handle[1];
				}
			} elseif ( ! isset( $this->registered[ $handle[0] ] ) ) {
				$this->queued_before_register[ $handle[0] ] = null; // $args

				if ( isset( $handle[1] ) ) {
					$this->queued_before_register[ $handle[0] ] = $handle[1];
				}
			}
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
2.6.0Moved from WP_Scripts.
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.