Define an array of parameters to be injected into the script:
$script_params = array(
'myWidth' => get_option('my_width')
);
Localize the script via wp_localize_script
:
wp_localize_script( 'your-script-handle', 'scriptParams', $script_params );
scriptParams
now is a js object you can access from within the script:
alert( scriptParams.myWidth ); // the value from the PHP get_option call in the js
Related Posts:
- WP_enqueue_script inside shortcode?
- How to enqueue script based on post category?
- Enqueue Scripts / Styles when shortcode is present
- Conditionally Loading JavaScript/CSS for Shortcodes
- How to add stylesheets only to pages with specific shortcode?
- Tinymce – How to hook before or after live shortcodes rendering?
- How execute shortcode with javascript
- Including javascript for a shortcode
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- Can’t get JS code to work with shortcode
- How resource intensive is wp_register_script()?
- How to handle shortcodes when using the JSON API
- Pass javascript array to shortcode
- shortcode causing the_content() to return blank?
- Add custom setting that uses radio button to WP Gallery
- Convert HTML Script to Shortcode [closed]
- Get Required Assets (JS, CSS etc) for post using REST API
- How to force that styles are enqueued in the header?
- Scripts for shortcode: concatenate or load separately? [closed]
- Adding javascript actions to words in post content
- Conditionally Loading JavaScript/CSS for Shortcodes
- Adding JS in header when using wp_enqueue_script in a shortcode
- Redirect to another page using contact form 7? [closed]
- Add JS in footer via shortcode?
- Deactivate JS Script in Plugin Shortcode
- Displaying shortcode output through Options Framework
- enqueue script with get_shortcode_regex
- Regenerating WordPress shortcodes based on value with AJAX
- WordPress Shortcode / Only works in classic editor, gutenberg error / invalid json response
- Using shortcodes in the Site Title
- wp_enqueue_scripts does not work on admin page
- Displaying an interactive web map on my wordpress site
- Multiple shortcodes with embedded JavaScript code in same page, how?
- Simulate shortcodes with javascript
- Clarify: Enqueueing scripts within shortcode only loads in footer?
- wp_register_script and wp_register_style when shortcode is used
- WordPress shortcode select option not working [closed]
- shortcodes output before content [duplicate]
- Can I strip HTML tags in the “Compare Revisions” screen?
- shortcode_unautop shortcode not functioning
- Shortcode perfomance solution
- How can I run shortcode after click with ajax
- Execute shortcode within shortcode
- wp_enqueue_script isn’t connecting my custom js file
- How get a shortcode working in category description
- display shortcodes outside of the_content
- Disable oEmbed for a Single Shortcode or at Least All Internal Links
- How to check if this is the nth instance of a given shortcode in a post
- Shortcode But Without The Equals Sign?
- Shortcode output is screwed up when arrow symbol “
- shortcodes between square and curly brackets
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- How to Get a part of URL and put in shortcode?
- Get shortcode attribute outside of WordPress
- Overriding shortcode $atts for featured products
- get_shortcode_regex() only matches first shortcode
- Looking for a way to include/embed text from a file on a page so that the short codes are processed
- Create shortcode in WordPress, using one variable in 3 functions?
- My shortcode does not call the function
- Shortcode not showing anything
- Correctly enqueue scripts of type=text/paperscript (PaperJs Library)
- How to create an incremental list using shortcodes?
- How to Make Archive ShortCode
- Do I just put the html in a page when enqueueng or do I also have to reference js file from the html page [closed]
- Are Shortcode Attributes Always Passed As Strings?
- wp_editor not rendering the shortcode
- Default WordPress shortcodes not working?
- How to make this shortcode work for post content wordpress [duplicate]
- stop WordPress removing shortcode from content [closed]
- caption shortcode using image alt as caption
- Sanitize or treatment of string in editor via shortcode
- Is it possible to handle two or more shortcodes in a single page?
- Toggle Shortcode Sanitize Title
- Execute Shortcodes when submitting post
- Substituting value via shortcode
- Can’t render shortcode when html tag contains hyphen
- Shortcode to appear and show the date not code in Title and description of Social Media sites
- Not to escape a text
- how to add shortcode widget at end of main blog page
- Shortcode result appears above page content
- How can I use javascript in specific posts without relying on a plugin?
- Shortcode is not showing content when placed in editor (post_type = page)
- How to insert a short code into Contact Form 7 in WordPress that will call a function once the submit button is pressed
- Multiple shortcodes only use attributes from one of the shortcodes on custom plugin
- Cannot modify class property from shortcode handler function
- How do i remove Business feeds Shortcode fatal error
- Can’t place endwhile in the loop properly in a shortcode
- How to reduce the image size inside an icon? [closed]
- How to insert visual compser post grid shortcode in a custom page template? [closed]
- latest posts shortcode with image
- JavaScript and Google PageSpeed + wp_enqueue_script
- Shortcode tags appear on mobile themes
- Video shortcode inside tabs shorcode NOT working
- Str_replace using shortcode with multiple changes
- WordPress do_shortcode first iteration
- Add a short code to a plugin
- Add widget/shortcode to sidebar OUTSIDE of the theme
- bootstrap-slider.js by seiyria not working in wordpress
- How to remove https:// from shortcode generated url
- How to enable on custom shortcodes