Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_localize_script [ WordPress Function ]

wp_localize_script ( $handle, $object_name, $l10n )
Parameters:
  • (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.
Returns:
  • (bool) Whether the localization was added successfully.
Defined at:



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.

Source


<?php
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 );
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics