How to inject variables into public-facing JS using wp_enqueue_script

Question

I’m using wp_enqueue_script to enqueue the public-facing JS of my WP plugin:

wp_enqueue_script($this->PluginName, plugin_dir_url(__FILE__) . 'js/public.js', array(), $this->version, false);

And in the other side I have:

var data = {
  name: ''
}

I would like, somehow, to set the name value to a value that I have access in the server side. Is this possible? Can someone point me to the documentation or an example of how to do that?

0
Amanda Ferrari 2 years 2020-10-22T11:10:29-05:00 0 Answers 11 views 0

Leave an answer

Browse
Browse