wp_localize_script

SummerySummery

Localize a script.

Syntax

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

DescriptionDescription

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,
    ...
}

ParametersParameters

$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.

ReturnReturn

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

SourceSource

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


			

ChangelogChangelog

Changelog
Version Description
2.2.0 Introduced.

See alsoSee also

Scroll to Top