Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can anyone tell me what the "$handle" ( first parameter ) of wp_localize_script is normally used for. Thanks.

P.s.: I have no idea why but stackexchange is telling me this question dosen't meet quality standards.

Edit: When i put in my ps it accepted it so i suppose it's the length of the quesion.... if you feel like this is an unacceptable question then apologies

share|improve this question
    
@kaiser was the edit you did to do with the problem i was having - eg something to do with how i wrote the code in the post - i will go look it up in the faq –  byronyasgur Jun 23 '11 at 22:00
add comment

3 Answers

up vote 3 down vote accepted

It's basically a unique id of the script you registered or enqueued before.

Let's say we enqueued a two scripts with wp_enqueue_script():

wp_enqueue_script( 'my_script_1','/js/some_script.js' );

wp_enqueue_script( 'my_script_2','/js/some_other_script.js' );

Now you want to pass your $data to the script #2 with wp_localize_script():

wp_localize_script( 'my_script_2', 'my_script_2_local', $data );

After this - when WordPress prints out your my_script_2 it will print out your $data variables along with it so you can use them in your script.

As you can see my_script_2 is our handle here - it makes the link between our script functions.

share|improve this answer
add comment

The handle is arbitrary (as in not technically meaningful) name of script that is used for human convenience when declaring it with wp_register_script()/wp_enqueue_script().

So first you declare script (or look up handle of already declared one) and then you can use handle to assign localization object to it with wp_localize_script()

share|improve this answer
1  
Seems like I can't answer a single Q today. Everybody beats me by seconds :) –  kaiser Jun 23 '11 at 20:59
1  
@kaiser Wow guys you're fast!! Nice to see you. –  Michal Mau Jun 23 '11 at 21:00
1  
@Maugly we sit in the chat and it pokes us about new posts :) –  Rarst Jun 23 '11 at 21:06
add comment

$handle is for all the script and style functions the given name.

// @example: 
wp_register_style( 'my-example-script', '/path/to/scripts/script.js', 'etc.' );

Then you can use it like this:

wp_enqueue_style( 'my-example-script' );
// or
wp_localize_script( 'my-example-script' );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.