Summery Summery

Localize a script.

Syntax Syntax

wp_localize_script( string $handle, string $object_name, array $l10n )

Description Description

Works only if the script has already been added.

Accepts an associative array $l10n and creates a JavaScript object:

"$object_name" = {
    key: value,
    key: value,

Parameters Parameters


(Required) Script handle the data will be attached to.


(Required) Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.


(Required) The data itself. The data can be either a single or multi-dimensional array.

Return Return

(bool) True if the script was successfully localized, false otherwise.

Source Source

File: wp-includes/functions.wp-scripts.php

 *     "$object_name" = {
 *         key: value,
 *         key: value,
 *         ...
 *     }
 * @see WP_Scripts::localize()
 * @link https://core.trac.wordpress.org/ticket/11520
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.


Changelog Changelog

Version Description
2.2.0 Introduced.

See also See also


Leave a Reply