![]() It might be worth diving into the Google Maps API to see if they emit any kind of loaded event we can listen to. On the other hand, if we don't use the callback technique, we'll need to implement some kind of listener that checks when the API is loaded. Instead of passing in an empty array to specify no dependencies for the script, the array contains a blank string. If we continue to use this technique, dequeuing the API call will also disable our maps. ![]() We are passing an initialize callback to the API as a query var, so that our maps spin up as soon as the API is loaded. This presents a bit of an issue around how the maps are loaded. So they need to be able to dequeue the API script without disabling the map view in our plugin. If another plugin enqueues the Google Maps api as well, this can cause conflicts, for example with Modern Tribe's Events Calendar plugin. This improves page load speed a little bit, but the cost is that it's very difficult to manage conflicts. My understanding is that Google Maps API shouldn't require jQuery to work so I'm not sure if this bit of extra info is relevant.Right now the plugin injects the Google Maps API script after the page is loaded. One thing I have noticed, is that if I put a dependency in for googlemaps it DOES print the tag I'm expecting but brings up this error in the console: initMap is not a function. I've tried changing the order in which it is enqueued. You can specify multiple pin locations and is a visual and useful. I've tried clearing my browser cache and using a different browser. The Divi Map Module is an easy way to display an interactive Google map on your website. I'm not sure if it makes a difference but I'm working locally and running MAMP. 1 Answer Sorted by: Reset to default 2 As charlietfl stated about dependencies. But when attempting to enqueue/register the Google Maps API in functions.php it doesn't seem to be adding the for the Maps API under the footer as it does for other enqueued items. then make your sage file a dependency of google maps in wpenqueuescript charlietfl. Moving the initMap() function to scripts.js works fine. This tutorial shows you how to add a simple Google map with a marker to a web page. Moving the styles to style.css works fine. How to add a map to your website with JavaScript. The second step was moving that code out from the front-page.php and placing it in functions.php, scripts.js, and style.css. The first step in the exercise was to place Google's sample code (script & styles) directly into front-page.php and the map displayed fine. Google is converting the hex code back into a simple & before parsing the parameters. Interestingly this line does appears in the head when I enqueue googlemaps: Calling Google Maps API, at least for version 3.X and higher, works correctly with &038 in the URL. '/js/scripts.js', array('jquery'), '1.0.0', true) Īdd_action('wp_enqueue_scripts', 'lapizzeria_styles') Īnd this is the HTML that is output below the footer (I believe I should be seeing a link to the Google API here): Wp_register_script('script', get_template_directory_uri(). ![]() Wp_register_script('fluidboxjs', get_template_directory_uri(). This seems to do the trick with Divi builder hanging. ![]() And take your Google Map API Key out As this is already included in the WPgoogle maps Advanced Tab settings. This is a snippet from my functions.php: wp_register_script('googlemaps', '', array(''), '', true) If anyone is using the divi theme or builder Turn of the Enqueue Google Maps Script in the div options page. Detecting request type in PHP (GET, POST, PUT or DELETE) 1116. There are also no errors in the developer console either. Loading Google Maps API with wpenqueuescript. When I register/enqueue the script, it doesn't appear in the HTML source code when viewing the page. I'm quite new to WordPress and I'm following a Udemy course on theme development and one part involves using the Google Maps API.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |