You can send variables to your script with wp_localize_script:
wp_enqueue_script( 'some_handle' );
global $post;
$my_meta = get_post_meta( $post->ID, 'my_meta', true );
$array = array(
'my_meta' => $my_meta
);
wp_localize_script( 'some_handle', 'object_name', $array );
You can then use the var in your script like:
object_name.my_meta
Related Posts:
- WordPress Visual Editor Stripping HTML Changes
- WordPress Admin Bar pushed Sticky Footer off the bottom of the page
- Add a class to links in the visual editor (how to get old dialog back)
- How to remove hardcoded characters from playlists?
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- Calling a method from functions.php on a click of a button
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- How to resize image on client-side before upload?
- Limit the Excerpt field in WP-Admin in words
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Handling an Ajax form submit
- Customizer Show/Hide Logo and Site Title
- API JSON Data in WordPress
- Use different javascript files for each page on website
- Using an Image Slider twice on the same page
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- Create custom blocks for bootstrap
- Click loads template via ajax
- How to speed up admin-ajax.php in wordpress
- JQuery not working on WordPress Admin page [closed]
- Sending jsPDF documents to the server
- Putting PHP variables into javascript [duplicate]
- How does this WordPress Plugin (Thrive Comments) apply their custom comment sort? [closed]
- js file in root loading without
- Ajax not working es expected (Returns 0)
- Use menu link or onClick to set a variable
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- Status 400 for AJAX POST Request with admin-ajax.php
- Incorrect MIME type for assets with Valet
- wordpress visual composer change grid builder post link
- PHP array to JS array to use in google map
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Media Upload , file name changed automatically
- Fancybox type popup window that’s not an iframe
- Generate sidebar depending on height of post
- how to make my website secured
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- How to correctly add Javascript to this PHP ‘Page Not Found’ Page?
- Error – ‘create_function is deprecated’ [closed]
- get taxonomy thumbnail and use it as a variable in code
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- element not working in Safari [closed]
- Is it save to use eval for a jQuery callback method coming from the database?
- Get html data with javascript to php array and store to wordpress database
- trouble with page_id & highlighting current page
- wordpress admin plugin menu custom css
- Load Posts on Click via Ajax into a DIV
- An audio player that showcase a random song from playlist every 24h [closed]
- How to Change CSS Colors from Custom Plugin Settings Page
- Passing the name of selected color from the custom component to `render_callback`
- After adding my website to a new server, I keep getting a unexpected end of file error, but the file is identitcal to it’s original source
- Why i can’t get custom fields value or post ID via Ajax?
- wp_localize_script() and JavaScript namespaces
- Cannot access $wpdb, comes back NULL
- How to reference PHP in Javascript
- How can I get my Media Uploader Button to function on 1 click rather than requiring 2 clicks?
- get db values for external js file
- Accessing an API with jQuery and AJAX
- Ajaxurl suddenly not defined
- WordPress – Get Posts with Category data
- How to store checkbox data for individual users?
- html form: redirect page after form completes submit function and posts data
- using shortcodes inside gravity forms
- Creating a brand attribute as a variable
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Add other class content with reference class value
- Gutenberg block don’t save rich text content
- Creating a POP Alert
- How do I integrate vanilla Javascript to a wordpress website?
- Hide Approved status for certain users in users list
- ACF values to Script with auto refresh
- WordPress Slider is not working
- Pulling Products from an API
- wordpress dependent dropdownlist using post type is not working
- Filtering markers on google map by WordPress category[SOLVED]
- Call jQuery function from PHP?
- How to echo a PHP code into WooCommerce variation product?
- How to call a function from functions.php with ajax?
- Custom Post type Ajax search results
- Ajax wordpress function showing source code in alert and not value of input field?
- Full search and replace isn’t enough to make all pictures to be loaded with https
- I want url from a file in media using title file
- scroll scrpit to particular button position to next id when click button
- Find the method which AJAX GET calls
- Retrieve $_POST data to send to javascript without using localize script
- Add a downloaded JS file to WordPress
- How to call javascript function (jquery) in a shortcode?
- Querying latitude and longitude into google maps correctly
- Why this plugin is not working?
- Trying to fix multiple category drop down
- js code not stored in database currectly
- Facebook share button only share the_permalink(), without thumbnail, tilte, excerpt, etc
- get_option(‘admin_email’) not working in wordpress when using ajax call
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- Passing javascript variable to php file
- Javascript code not working – $ is not a function error
- Disable Typed Parameters for JavaScript in PhpStorm? [closed]
- Losing Session ID and sessionStorage when navigating to other domains on Multisite
- bloginfo url in javascript
- Fetching only specific value from php file