Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Register the script
- wp_register_script( 'some_handle', 'path/to/myscript.js' );
- // Localize the script with new data
- $translation_array = array(
- 'some_string' => __( 'Some string to translate', 'plugin-domain' ),
- 'a_value' => '10'
- );
- wp_localize_script( 'some_handle', 'object_name', $translation_array );
- // Enqueued script with localized data.
- wp_enqueue_script( 'some_handle' );
- <script>
- // alerts 'Some string to translate'
- alert( object_name.some_string);
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement