Wrapper for $wp_scripts->localize().
Used to localizes a script. Works only if the script has already been added. Accepts an associative array $l10n and creates JS object: “$object_name” = key: value, key: value, …
See http://core.trac.wordpress.org/ticket/11520 for more information.
Signature
wp_localize_script( $handle, $object_name, $l10n )
- handle
- (string) The script handle that was registered or used in script-loader
- object_name
- (string) Name for the created JS object. This is passed directly so it should be qualified JS variable /[a-zA-Z0-9_]+/
- l10n
- (array) Associative PHP array containing the translated strings. HTML entities will be converted and the array will be JSON encoded.
Return
(boolean) Whether the localization was added successfully.
Source
function wp_localize_script( $handle, $object_name, $l10n ) {
global $wp_scripts;
if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
if ( ! did_action( 'init' ) )
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
return false;
}
return $wp_scripts->localize( $handle, $object_name, $l10n );
}
WP Trac GitHub Bitbucket
Link here
-
URL
http://queryposts.com/function/wp_localize_script/ -
HTML
<a href='http://queryposts.com/function/wp_localize_script/'>wp_localize_script()</a> -
Markdown
[wp_localize_script()](http://queryposts.com/function/wp_localize_script/) -
BBCode
[url=http://queryposts.com/function/wp_localize_script/]wp_localize_script()[/url]