WP_Script_Modules::print_import_map()

In this article

Prints the import map using a script tag with a type=”importmap” attribute.

Source

public function print_import_map() {
	$import_map = $this->get_import_map();
	if ( ! empty( $import_map['imports'] ) ) {
		global $wp_scripts;
		if ( isset( $wp_scripts ) ) {
			wp_print_inline_script_tag(
				wp_get_script_polyfill(
					$wp_scripts,
					array(
						'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")' => 'wp-polyfill-importmap',
					)
				),
				array(
					'id' => 'wp-load-polyfill-importmap',
				)
			);
		}
		wp_print_inline_script_tag(
			wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ),
			array(
				'type' => 'importmap',
				'id'   => 'wp-importmap',
			)
		);
	}
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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