multiple wp_localize_script calls in the same page
-
I don’t find a solution to my problem related to wp_localize_script, maybe someone has a solution. The problem is when I try to put more than one in the same page, for now I implemented it this way:
PHP
$example_arr = array( ‘example_id’ => ’123′ ); wp_localize_script( ‘example_handle’, ‘example_obj’, $example_arr );
JS
var id = example_obj.example_id;
this works well, for example I can use it in a shortcode like this:
[example id="123"]
but if I try to put more than one in the same page:
[example id="123"] [example id="456"]
only the last id is rendered, this is because ‘example_obj’ gets the last value of example_id
I tried to add an ID to ‘example_obj’ something like this: ‘example_obj’.$id
but I don’t know how to get it in JS, for example if I created 2 objects:‘example_obj123′ and ‘example_obj456′, how can I get these in my JS?
p.d. the ID it’s generated dinamically, not hardcoded like the example.
thanks in advance
- The topic ‘multiple wp_localize_script calls in the same page’ is closed to new replies.