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?
- How to: Easily Move a WordPress Install from Development to Production?
- Is there a flowchart for WordPress loading sequence?
- Best collection of code for your .htaccess file [closed]
- Essential technical features for high-end WordPress web hosting? [closed]
- How to remove admin menu pages inserted by plugins?
- How to put logs in WordPress
- How to get the Date Format and Time Format settings for use in my template?
- Where are Additional CSS files stored
- Best Practices for Regression Testing WordPress Websites?
- Remove wrapping div and ul from output of wp_nav_menu
- What Is The Use Of map_meta_cap Filter?
- get post author id outside loop
- Custom Walker: how to get ID in function start_lvl
- Creative uses of WordPress [closed]
- How to *remove* a parent theme page template from a child theme?
- Validating Custom Meta Box Values & Required Fields
- How do I make my child theme re-apply the settings that were customised when its parent was active?
- Multiple Inputs in a Customizer Control
- New WP_Customize API – how does it work under the hood?
- Embedding a SOAP Client into a WordPress Plugin?
- Is there anything that Joomla or Drupal can do that can’t be done in WordPress? [closed]
- Update widget form after drag-and-drop (WP save bug)
- Data sanitization: Best Practices with code examples
- How to benchmark a WordPress installation? [closed]
- Should I delete the default themes?
- Moving WP install from local to live, what about wp_posts GUID?
- Modified wp.media.view.Settings.Gallery in Backbone JS, but editing doesn’t work
- Running Gutenberg React in Development Mode
- Prevent WordPress from automatically installing a new theme each year
- Can we use one WordPress installation for multiple databases, domains and content directories
- Is there a blank theme framework compatible with WP 3.0? [closed]
- Plugin SVN & update API – how are plugins identified?
- Users with custom roles not showing in post author select box
- How to use more than 256MB of memory in the admin?
- How do register_sidebar() and get_sidebar() work together?
- How do you get formatted content of a post using the WordPress API?
- Localization: I want the backend: english and frontend in defined language
- What does l10n.js do in WordPress 3.1? And how do I remove it?
- Are there any forks of WordPress (and what is different about them)?
- How to Change 404 page title
- Make Custom Metaboxes Collapse by Default
- WordPress Paginate $wpdb->get_results
- Return $post_id when DOING_AUTOSAVE?
- Custom maintenance page
- Add button to TinyMCE bar without creating a plugin
- Why do I get the timeout warning?
- How to add a new product type on woocommerce product types? [closed]
- How to include own css on wordpress tinymce editor?
- How to disable page delete
- add button to post edit page when post_status=publish
- how to override woocommerce specific loop or archive-product.php [closed]
- Modify existing plugin function using filter (without modifying the plugin directly)
- Rename UPLOADS folder with custom WP_CONTENT_DIR
- WordPress hook before inserting post into database
- Any post install tips after installing WordPress 3.0.1?
- Making Custom Fields Standard in the Admin UI
- Remove WordPress theme from a specific page
- Version Control: Entire site or just pieces?
- Getting a stack trace when an error occurs?
- Check for and enforce unique value in user-entered custom meta field in WP Admin
- Backup the Database and Restore from the Backup?