wp_localize_script() – Localize a script.
You appear to be a bot. Output may be restricted
Description
Localizes a script.
Works only if the script has already been registered. Accepts an associative array $l10n and creates a JavaScript object:
- "$object_name" = {
- key: value,
- key: value,
- …
- }
Usage
$bool = wp_localize_script( $handle, $object_name, $l10n );
Parameters
- $handle
- ( string ) required – Script handle the data will be attached to.
- $object_name
- ( string ) required – Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
- $l10n
- ( array ) required – The data itself. The data can be either a single or multi-dimensional array.
Returns
bool True if the script was successfully localized, false otherwise.
TO DO
Documentation cleanup
Source
File name: wordpress/wp-includes/functions.wp-scripts.php
Lines:
1 to 10 of 10
function wp_localize_script( $handle, $object_name, $l10n ) { global $wp_scripts; if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { _wp_scripts_maybe_doing_it_wrong( wp_localize_script, $handle ); return false; } return $wp_scripts->localize( $handle, $object_name, $l10n ); }