Use wp_enqueue_script
from your PHP code to register and enqueue a script. WordPress will then handle automatically adding the required script tags at the right place and you’ll be able to instantiate and use the API from your javascript.
E.g. (untested, check the docs for your use case)
wp_enqueue_script('googlemaps', 'https://maps.googleapis.com/maps/api/js?&key=KEY');
Related Posts:
- Integrating PHP into Javascript to display map markers with Google API
- Run a Parallel PHP Application with WordPress
- Putting PHP variables into javascript [duplicate]
- 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
- PHP variables in a post?
- Filtering markers on google map by WordPress category[SOLVED]
- Generate a radius search of custom post type locations
- Querying latitude and longitude into google maps correctly
- WordPress Visual Editor Stripping HTML Changes
- 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
- Get post meta in enqueued js file
- How to use WordPress (PHP) functions in AngularJS partials files?
- How to create a custom config file and get data using inline JS in a wordpress page
- Handling an Ajax form submit
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- Archive dropdown styling not applied
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Use WordPress’s Media Uploader/ Manager in non WordPress php application
- Get/Set wp.customize.previewer.previewUrl
- How to speed up admin-ajax.php in wordpress
- How to make custom total price reactive in navigation
- Adding tawk.to code just before body tag on functions.php file
- How can I output a php value into a JS file within WordPress?
- How to test nonce with AJAX – Plugin development
- How does this WordPress Plugin (Thrive Comments) apply their custom comment sort? [closed]
- Slider loading issue
- Creating a Multi-Level Associative Object Using AJAX
- remove wp floating submenu in wp dashboard
- search and replace preword from author
- How to complete two other input fields, completed the first
- Need Help Fixing My Iframes [closed]
- wp_enqueue_scripts leads to error
- Passing UTM Parameters To Modify Page In WordPress
- Incorrect MIME type for assets with Valet
- Open post-content in archive page in a Modal box with bootstrap
- Creating own shortcode – echoeing php variable based on JS variable
- How to add a do_action on refreshing of WP customizer?
- PhantomJS with wordpress
- Add / Update Custom Fields After Select Pictures in Media Window
- Generate sidebar depending on height of post
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- Tell WP register script to load a script only when the entire page is loaded
- How do I get an external php page to load using javascript
- wordpress admin plugin menu custom css
- trying to put an active hover to my custom nav category buttons [closed]
- How do I get my Javascript scripts working?
- Why i can’t get custom fields value or post ID via Ajax?
- How to reference PHP in Javascript
- get db values for external js file
- Calling PHP Titles inside Javascript Markup
- Accessing an API with jQuery and AJAX
- Ajaxurl suddenly not defined
- ‘Bones’ theme: Load stock scripts in footer instead of header?
- Replacing WordPress Icons (menu,icons32, etc)?
- go to home page when i select default in select-box
- How to redirect non logged in mobile users to page on same site?
- html form: redirect page after form completes submit function and posts data
- Creating a brand attribute as a variable
- Decode and Decrypt Azure B2C OpenID Authorization Token, Use Response in API Call (Example Token Within)
- 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
- Add other class content with reference class value
- Exclude ipads and tablets form wp_is_mobile code
- gettint error 400 with AJAX
- Javascript / PHP – closing the loop
- I can’t load my images from a js file using wp_localize_script
- How to output values from a loop into a javascript array
- Pulling Products from an API
- Bring Font Awesome icons inside menu A tags
- Call jQuery function from PHP?
- custom post type column countdown
- How to call a function from functions.php with ajax?
- Pass product object to javscript
- Automatically refresh page if widget is added to page?
- number of posts with “Load More”
- Call custom JS function from PHP
- How to send Ajax Call from frontend without using wp_localize_script in Theme
- Complex PHP for json_encode > how to handle/output right?
- Slider from different widgets
- How to get values from wordpress listings and use them in javascript array?
- Why this plugin is not working?
- Trying to fix multiple category drop down
- Trying to customize wordpress drop down categories
- What’s the best way to format ACF number fields for display on the front end?
- get_option(‘admin_email’) not working in wordpress when using ajax call
- Import and use a variable in additional settings of Contact Form 7 [closed]
- Is there a better way to output HTML as a shortcode?
- Disable Typed Parameters for JavaScript in PhpStorm? [closed]
- Losing Session ID and sessionStorage when navigating to other domains on Multisite
- Slick slider not working on wordpress
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- Facing Problem While Running WordPress Hook For Archive, Categories, Author, Date Pages Only
- Start a long running PHP process via JS/Ajax and monitor progress on admin page
- Retrive the value of the Active variation of the product and then link it to the “read more” to dynamically change
- JQuery UI Autocomplete showing as bullets
- How to make this shortcode not refresh the whole page when i use it on frontend