function wp_localize_script( $handle, $object_name, $l10n ) {}

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.


  • string $handle: The script handle that was registered or used in script-loader
  • string $object_name: Name for the created JS object. This is passed directly so it should be qualified JS variable /[a-zA-Z0-9_]+/
  • array $l10n: Associative PHP array containing the translated strings. HTML entities will be converted and the array will be JSON encoded.

Return values

returns:Whether the localization was added successfully.

Source code

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 );



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: