1// Register the script
2wp_register_script( 'some_handle', 'path/to/myscript.js' );
3
4// Localize the script with new data
5$translation_array = array(
6 'some_string' => __( 'Some string to translate', 'plugin-domain' ),
7 'a_value' => '10'
8);
9wp_localize_script( 'some_handle', 'object_name', $translation_array );
10
11// Enqueued script with localized data.
12wp_enqueue_script( 'some_handle' );
13
1<?php
2function pw_load_scripts() {
3
4 wp_enqueue_script('pw-script', plugin_dir_url( __FILE__ ) . 'js/pw-script.js');
5 wp_localize_script('pw-script', 'pw_script_vars', array(
6 'alert' => __('Hey! You have clicked the button!', 'pippin')
7 )
8 );
9
10}
11add_action('wp_enqueue_scripts', 'pw_load_scripts');