Use wp_localize_script
:
wp_enqueue_script('YOUR_SCRIPT_HANDLE');
$object = array(
'zoom' => get_option('map_zoom'),
'longitude' => get_option('map_longitude'),
'latitude' => get_option('map_latitude'),
);
wp_localize_script('YOUR_SCRIPT_HANDLE', 'JSObject', $object);
And then use it in your JS file like JSObject.zoom
and the like.
Related Posts:
- PHP variables in a post?
- Integrating PHP into Javascript to display map markers with Google API
- Run a Parallel PHP Application with WordPress
- Pass PHP variable to JavaScript without inline JS
- Integrating PHP into Javascript to display map markers with Google API – problem with wp_localize
- PHP array to JS array to use in google map
- How to add drag and drop functionalities to a div inside option panel
- How to reference PHP in Javascript
- Unable to display multiple parameters from url by javascript through shortcodes
- Trying to add some custom text into WordPress Post title via function.php
- Filtering markers on google map by WordPress category[SOLVED]
- How to find php variable of wordpress theme settings
- Generate a radius search of custom post type locations
- Querying latitude and longitude into google maps correctly
- Import and use a variable in additional settings of Contact Form 7 [closed]
- How can i add a script with parameters?
- Send an e-mail on address with the link with disliked post
- Settings API form – submit with AJAX
- How to extend SelectControl with data from my theme
- Woocommerce disable order item link (backend) [closed]
- Post form – AJAX won’t upload featured image – Plugin development
- Integrate admin plugin into template. Very interesant (live search + autocomplete with wp rest api, in vanilla js)
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Search bar for wp menu
- Adding HTML Code to Replace Text in PHP
- Show next image in array if page is revisited by same logged user
- How to check a variable Changes
- How to add JS script in specific pages in WordPress?
- Executing php on button press
- Add other class content with reference class value
- Load more posts using AJAX based on posts inside WP_Query
- Exclude ipads and tablets form wp_is_mobile code
- How to call my PHP function with AJAX ? wp_query
- Fetch Data from an external MSSQL Database in a Managed WP hosting
- Run do_shortcode on php template using JS function
- global $product is empty string when passed into function
- Gutenberg block don’t save rich text content
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Using Google Analytics in an enqueued JS file
- Creating a POP Alert
- Create a WordPress Contact Form to call a POST AWS API Gateway and send user data
- Admin-ajax.php 404 error
- How can i find wrong word in search box and replace with correct word
- How to pass values from one function to the other using an array variable
- Custom global variable not working in function
- separate list of programs in html/javascript coming from php
- How do I integrate vanilla Javascript to a wordpress website?
- WordPress How do I pass a variable from one add_action to another?
- How to use wp_ajax_set_post_thumbnail?
- Best way to use variables in multiple functions?
- Passing a value from an input field to a php function in WordPress?
- Hide Approved status for certain users in users list
- How do I disable cache for a certain page?
- How To Get HTML Eelement From Another Page
- Ajax search box displays nothing if taxonomy doesn’t exist
- Display one random image from Media Library
- Conditional Banners
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- ACF values to Script with auto refresh
- Update $wpdb query with AJAX
- Google CSE Malfunctions via Chrome/Safari on Mobile When Clicking on Either Search Icon/Menu Icon. How to Make Google CSE Default Theme Search
- I have a lot of JavaScript erorrs after SSL someone can help me?
- $.ajax results in 403 forbidden
- WordPress Slider is not working
- How can i show specific Category List?
- Using Javascript On Page – Header and Footer Now Missing
- Store data from JavaScript object to custom table in user account
- How do I fix Undefined variable using $_POST in function?
- register dependency css and js inside a plugin class
- Filtering custom posts by using checkboxes for taxonomy in an ajax loop always gives server 500 error
- AJAX to add to cart multiple products woocommerce
- Change CSS Variable value in Theme Customizer Live Preview
- gettint error 400 with AJAX
- Using wp_editor() when not logged stopped working
- Modifying child theme’s header
- Adding extra data to shortcode attributes and pass it to JS with wp_localize_script
- How to change the value of a variable using input field?
- Show the subcategory name based on current product
- Show subcategory name selected in specific category woocoommerce
- Javascript / PHP – closing the loop
- Filter portforlio with librairie isotop
- I can’t load my images from a js file using wp_localize_script
- Javascript Tab Gallery with Advanced Custom Fields
- How to output values from a loop into a javascript array
- Pulling Products from an API
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- sessionStorage saves input value in browser but it is not loaded in the form field
- Collapsible menu on post sidebar only expands and does not collapse
- Replacing entire tag with shortcode – JavaScript [duplicate]
- wordpress dependent dropdownlist using post type is not working
- Move Jquery.js to Footer
- Bring Font Awesome icons inside menu A tags
- How do I make comment-reply-button with that takes to comment reply form on click
- Call jQuery function from PHP?
- custom post type column countdown
- How to echo a PHP code into WooCommerce variation product?
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- How to call a function from functions.php with ajax?
- ajax polling with admin-ajax.php
- Pass product object to javscript