wp_localize_script $handle

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.

Leave a Comment