WP_Script_Modules::print_import_map()publicWP 6.5.0

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

Method of the class: WP_Script_Modules{}

No Hooks.

Return

null. Nothing (null).

Usage

$WP_Script_Modules = new WP_Script_Modules();
$WP_Script_Modules->print_import_map();

Notes

  • Global. WP_Scripts. $wp_scripts The WP_Scripts object for printing the polyfill.

Changelog

Since 6.5.0 Introduced.

WP_Script_Modules::print_import_map() code WP 6.5.3

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',
			)
		);
	}
}