WP_Script_Modules::print_script_module( string $id )

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Prints the enqueued script module using script tags with type=”module” attributes.

Parameters

$idstringrequired
The script module identifier.

Source

private function print_script_module( string $id ) {
	if ( in_array( $id, $this->done, true ) || ! in_array( $id, $this->queue, true ) ) {
		return;
	}

	$this->done[] = $id;

	$src = $this->get_src( $id );
	if ( '' === $src ) {
		return;
	}

	$attributes = array(
		'type' => 'module',
		'src'  => $src,
		'id'   => $id . '-js-module',
	);

	$script_module     = $this->registered[ $id ];
	$queued_dependents = array_intersect( $this->queue, $this->get_recursive_dependents( $id ) );
	$fetchpriority     = $this->get_highest_fetchpriority( array_merge( array( $id ), $queued_dependents ) );
	if ( 'auto' !== $fetchpriority ) {
		$attributes['fetchpriority'] = $fetchpriority;
	}
	if ( $fetchpriority !== $script_module['fetchpriority'] ) {
		$attributes['data-wp-fetchpriority'] = $script_module['fetchpriority'];
	}
	wp_print_script_tag( $attributes );
}

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.