+1 954 232 1578    or   +45 3699 1578 me@larsik.com

How to parse GET or POST variables to JavaScript via PHP

For a customer I had to find a way to parse $_GET or $_POST variables to a widget running JavaScript code on another server.

I used a piece of code by Pippin Williamson to only load the necessary javacript script if the shortcode is used on the page we’re viewing.

Load Scripts if Post has Short Code.

My modified version looks for a specific paramater ?restid=, and if it exists loads the JavaScript file with the parameter parsed via the wp_localize_script() function. This way the .js file can use that value to continue processing.

https://gist.github.com/lkoudal/8dd02ced21f5fdb334ee

The jQuery code is here:

Related post
How to: De-minimizing CSS to readable format
Share This

Share This

Share this post with your friends!