I’m creating a plugin that uses jQuery to modify some css, but what I can’t figure out is how you can control the execution of the jQuery with WordPress plugin options (like checkboxes true/false). Can WordPress options be used as “variables” in jQuery? Or would every case require a unique .js file?
Leave a Reply
You must be logged in to post a comment.
Variable can be passed to jQuery or any javascript using
wp_localize_script
.Example:
How to get the variables in your javascript:
WordPress will output your variables between
<sript> </script>
tags before enqueuing the javascript file so they will be available to use.See wp_localize_script from Otto on WordPress for more information.
Edit:
Try adding the variables to a function that returns the value. I’m using the exact code below and it works.
The function that returns the variables below: