You don’t specify how precisely your JS is output. If you are doing this inline from PHP you could just echo required data in place.
If it’s just some arbitrary script, loaded as such, then the common practice in WP is to use wp_localize_script()
to pass data from PHP runtime to an enqueued script.
While by initial purpose (and name) the function was meant for localization, it handles arbitrary data just fine.
Related Posts:
- show hide image script after 4 seconds [closed]
- Set default image link target in Gutenberg image block
- How to modify image editor dialog options on WordPress?
- Graphing libraries for WordPress [closed]
- 3.5 media.editor: what is the event listener for choosing an image?
- JavaScript and images files are not recognized
- Multiple images with Media Uploader on front-end
- Update an image block style programatically
- How can I use cached images in an AJAX response?
- Help to upload post attachments from Ajax
- Image LazyLoad plugin not loading jQuery dependancies with wp_enqueue_script in WP 3.3.1
- How to use Facebox in WordPress theme?
- Howto use WP built in Thickbox for images?
- How to get the image-URL from Media-Upload in a post?
- Using jQuery to automatically add class only to gif images in WordPress database [closed]
- How do I include javascript/jquery image resizing with wordpress?
- Fancybox just loading small white square
- Image modification
- Hide Title tag on image Hover
- Landing Page with HTML CSS JS and Images on wordpress
- Built-in image lazy loading: Does it come with a polyfill for older browsers?
- Access html element in media modal with jQuery
- Images names not inserting in WordPress Database from Dynamic Add / Remove fields
- js alert in add_filter function for image_send_to_editor
- WordPress Javascript displaying an image Question
- Issues Adding a jQuery Image Slider
- Select image and display from textfield?
- Thickbox not displaying just the image, instead showing full page in lightbox
- 3.5.x Theme Customize: Handling Custom Control Requests
- WordPress: Preload next post images
- Theme using masonry layout script rendering overlaped images in Google Chrome [closed]
- Script not working in WordPress [duplicate]
- Cannot read property ‘push’ of undefined when combining arrays
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- Convert CSV data into JSON format using Javascript
- Defining a HTML template to append using JQuery
- jQuery select option elements by value
- get attachment title based on attachment id
- Media Upload Folder – how to manage
- Wrong image dimensions in Insert Media after add_image_size()
- PHP Fatal error: Call to undefined function download_url()
- Upload multiple images in a custom metabox
- How can I hide media library images from general users?
- WordPress loads whole jQuery UI library
- Rename image during upload using date and time stamp?
- Get author ID with attachment ID
- Show Post Excerpt in Image Attachement
- WP 3.4 has missing photo data
- How to add image id class?
- wp_get_attachment_url with specific image_size?
- Get meta data from image
- Shortcode for a link and thumbnail
- Bulk edit Gutenberg single images to change from linking to media file to attachment page
- Fuzzy Images in WordPress 4.4
- In Wordress one author can not see the other’s author uploaded images through media library
- How to add missing dimensions to all images to avoid cls?
- Prevent Image Pasting in RichText Component
- Add new image block, set default class name and update it using Javascript
- Why are images created by WP larger than the original uploaded image?
- Default Image Link Type Setting not Working
- Replace image caption with its title and description
- Removing featured image from gallery?
- videopress videos are not displayed when loading the content with ajax in a lightbox
- Is it a good practice to change media settings on theme activation?
- Function to remove all classes on images inserted into posts?
- How to get the real file type for images that do not have an extension
- Images don’t update after being edited
- Display post image in a size defined by add_image_size()
- How to change the text of the “You are about to permanently delete these items…” alert message when deleting media from the media library?
- Twenty Fifteen: Change navigation menu behavior
- JQuery needs to be defined in , but Gravity Forms is defining it in the
- IMG size is set to width=”964px” or “100%”, but is shown as “634px” in browser
- big trouble with javascript
- Using WP functions inside javascript
- Covert WordPress Blogname into JQuery
- get rid of random string before an for an image path on wordpress
- Using srcsets in a custom block
- Product Gallery Images to go into full size on Product Page
- How to Display Image Caption but Not Alt Text
- I want to create a hero image with text and a button on my front page. How can I do this?
- Why image Thumbnail url is not displaying with custom size?
- add_image_size limiting sizes (???)
- Automatically generate multiple image sizes for element
- Is it possible to remove spaces from existing images? [closed]
- Why doesn’t WordPress make thumbnails for videos?
- Thumbnail gallery by date and taxonomy
- Uncaught TypeError: undefined is not a function (shortcode-box)
- Adding multiple images on my site – without using plugins [closed]
- > added to images link in WordPress
- Image media upload problem in page editing modus?
- Thumbs and pictures not showing anymore
- Is there a good way to use CMS images with CSS
- Upload image from other server without resize?
- Images will not attach to posts after site migration
- How to access & display images from a post without textual content ( and vice versa) according to best wordpress practices
- Forcing absolute src links in the RSS feed
- how to embed a crop feature for cropping images uploaded by the user
- Uncaught Error: Call to undefined function file_is_valid_image()
- Remove one srcset entry from wp_get_attachment_image