Consider using the Localize script in WordPress
<?php
// Register the script
wp_register_script( 'some_handle', 'path/to/myscript.js' );
// Localize the script with new data
$translation_array = array(
'some_string' => __( 'Some string to translate', 'plugin-domain' ),
'a_value' => '10'
);
wp_localize_script( 'some_handle', 'object_name', $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( 'some_handle' );
You can find more details here, wp_localize_script
Related Posts:
- How to make a script load after Custom Block is loaded in the editor?
- When using the block.getSaveElement hook can you output different markup based on whether or not you are in the edit view or the live page view?
- simple expandable vertical menu, java script problem
- How to use get_option() without any filter?
- dynamic external javascript generated using php
- Widget Javascript code (ajax)
- How to link external JavaScript files?
- add JS to multiple plugin admin pages
- Adding custom styles to dropdown in editor
- Create simple Cookie Box for WordPress
- how to add custom css and js on wordpress post editor directly without using .php file
- Javascript Solution Remove Specific Tag but leave the rest in a specific DIV
- window resizing problem
- Adding custom field in all widgets, but at the top of the form, in admin area
- Load MediaPlayerElement after Infinity Scroll loads more posts
- Include custom JS without child theme
- Custom Login Process
- How to stop displaying the Id without losing the functionality
- Upload a web module (html and JS) to wordpress
- How to add WordPress JS Script Links
- custom css and javascript not working on page defined as template?
- wp_enqueue_script JS code runs too late (after user begins interacting)
- custom email validation using javascript api with elementor pro and code snippets
- javascript file not working in a plugin template file
- Javascript Tooltip not fully working on my wordpress page
- Where to put coding a validation script for store? [duplicate]
- WordPress Customizer: Check for value of CSS selector and replace it
- How to submit form data in the same page in WordPress without reloading the page?
- how to auto fille conatct form 7 when user is logined
- Multi-site customization
- Pass the post ID
- Document.body.scrollTop in WordPress
- Adding Custom HTML/CSS/JS code in specific page
- Making custom pages (with an example to explain the goal)
- Add variable : 1 Week ago
- Prevent posts from being published if the ‘Uncategorized’-category or no category is selected
- Particle.js not loading in WordPress Gutenberg
- Changes to code not displaying
- Multi color post title by using custom javascript inside the gutenberg editor?
- Is there a flowchart for WordPress loading sequence?
- How do register_sidebar() and get_sidebar() work together?
- Add a class to links in the visual editor (how to get old dialog back)
- How to customize the default HTML for WordPress Attachments
- Is it possible to change the attributes of a registered style or script before it fires?
- how to change “published date” format on edit.php (Posts page)?
- How to change submit button value in comment from “Post Comment” to “Send”
- WordPress custom post types breaks permalink on theme reinstall
- Creating a searchable A-Z listing of hundreds of companies/services
- Show attribute description when filtering by that attribute
- Customize in category page
- How to get WordPress to accept the tag in articles (or other alternatives)
- Add custom column to Users admin panel with Types user custom fields?
- How do I change the default admin color scheme in MP6
- woocommerce Add custom field set like billing fields
- How can a single line in a blog post take down my server?
- Calling a php file from a javascript file in wordpress
- Adding a Table to the wordpress database
- how can I change the background color of all posts on my server?
- Auto redirect after session expire, but only for one user
- Custom title, Bones theme
- How does WordPress determine which multisite the user is on from the URL?
- How to create a completely private wordpress with multiple membership levels
- Why do posts disappear from admin after upgrading from WP 2.7.1 to 3.0.1?
- How to change the category url jusy show /category/%category_id% in wordpress?
- custom meta box for page default template
- How can I display a PHP foreach loop’s answers by AJAX
- Child Theme with multiple css files
- “An automated WordPress update has failed to complete – please attempt the update again now”– But there is no .maintenance file
- How do I redirect a post url to a custom url?
- How to customize
- Why the css in twenteenfourteen-child theme take no effect?
- Modify files without losing customization after updates
- Determine if action was executed in functions
- Extending core class in plugin
- Is it possible to make wordpress LMS
- Saving contact form 7 data into custom Table
- Hiding Short Description in Shop Page, WooCommerce
- theme customizer – can a single option pass multiple values?
- Separate header for static home page and posts page
- Media Upload not working after hiding some elements from functions.php
- Customizing the gallery of the post correctly
- Will WordPress updates remove Gutenberg Additional Classes?
- WP_Query – sort the results by meta value custom attribute wocoomerce
- Multiple header style under meta box
- How can I create a Custom Page? (not a page template!!)
- How to have different background image based on post category
- How to compare number with id of post in certain category
- Custom stylesheet not loading
- Custom Admin Section
- Header image doesn’t show up on page
- How to get name and email value from a custom form and add it to campaign monitor subscriber list?
- Create a google friendly header with text and logo
- Disallow “contributors” to edit their own posts once they’ve been set to “Pending Review”
- Custom Link In WordPress Media “Attachment Details” Upload Screen
- “Static” pages within a theme
- Custom WordPress SQL Query 4 posts per custom taxonomy
- Disable all Fonts that are Standard in WordPress and replacing them with a custom Font?
- Custom product sorting archive page
- Add custom information in editor summary
- A Voting system for a pageants