1. Home
  2. Docs
  3. Simpods MVC
  4. Tutorials
  5. JavaScript
  6. Passing Variables To JS From Controller

Passing Variables To JS From Controller

Variables can be passed from a controller to JavaScript using the WordPress function wp_localize_script(). As the script needs to be registered before this function can be used it is normally used at the end of the controller’s enqueue() method or a method called from there.

Auto-enqueued scripts

Scripts that are automaticity enqueued are loaded after the controller’s enqueue() method. To pass variables to these scripts a separate method must be used that is hooked to the wp_enqueue_scripts action with a priority value of 11 or greater.