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]
- Where to get information about array fields in $_REQUEST?
- Variables declared in header not available in other includes
- WordPress Infinite Scroll without using any plugin
- Create Image Uploader for Widget
- WordPress Ajax always returns a 404 error
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- reason of splitting theme files to multiple files
- 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
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Passing PHP Variables to JS using Localize Script
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Customizer Show/Hide Logo and Site Title
- Use different javascript files for each page on website
- Create custom blocks for bootstrap
- Click loads template via ajax
- Sending jsPDF documents to the server
- Set WordPress Default Template
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- AJAX request status 200 but no actual “response”
- Adding custom directory and PHP files in wordpress
- How can I Add a variable PHP in the Menu Nav
- Get value from shortcode to do something
- WP Post-Thumbnail
- Save Search System
- dynamic dependent select dropdown
- Ajax load more button for comments wordpress
- PHP, Creating a dynamic variable
- How to pre populate a form field with a link of a current user’s author profile?
- parts of url disappear when using # inside href=”” [closed]
- How do I Import / Upload Files with jQuery AJAX?
- Noscript not working as it should in wordpress site
- Variable not staying set
- PHP echo inside javascript
- How to add API security keys into JS of wordpress securely
- HTML escaping data with ajax requests
- Warning: Illegal string offset on theme options page [closed]
- 2nd page displaying the exact same posts as my first page (minus the very first post)
- Link blogname and blogdescription to the Options Framework
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- How to use wordpress function wp_enqueue_script() in php?
- Get related product based on subcategory selected from category id with ID 142
- wp_nav_menu not working correctly in my underscores theme
- url_to_postid returns 0
- How do i add slugs to a URL, but still redirecting to the same page
- how can I include some custom variable from functions.php?
- Link to page with posts of specific type
- implementing a jQuery “click to expand” link in WordPress [closed]
- random reason on refresh
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Using theme options to change a border-radius value
- Some problems in custom widget
- Call a function in functions.php from within tags (JS)
- Hook on file upload
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- WordPress Search Ajax + Isotope + InfiniteScroll
- WordPress User Meta value variable into Google Gauge Chart
- Show next image in array if page is revisited by same logged user
- How to call my PHP function with AJAX ? wp_query
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Create a WordPress Contact Form to call a POST AWS API Gateway and send user data
- Admin-ajax.php 404 error
- 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 can i get the same ajax result using WP REST API instead of admin-ajax?
- Target a specific container to style on WordPress storefront theme
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- How to create a radio button to alt between settings in wp_options table
- Where can I find the declaration of `$_wp_theme_features`?
- customizer live preview layout picker
- I need help implement a Javascript code into the PHP file
- Admin bar nodes
- How can I correctly POST to a WordPress page?
- Not able to call class in NHP framework
- if is_home(), change class of menu-item-225 of wp_nav_menu
- If I define a variable in header.php, how do I make it available to templates?
- Load php function with AJAX on modal window
- Select area and checkbox data is not saving?
- JSON Object Value Show Undefine
- Facing Problem While Running WordPress Hook For Archive, Categories, Author, Date Pages Only