![]() ![]() 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. 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 have google maps JS API script enqueued succesfully, with its API key in app/setup.php. Doing the same as in Sage 8, doesn’t work in Sage 9. I've tried changing the order in which it is enqueued. Trying to get Google maps JS API working. I've tried clearing my browser cache and using a different browser. I'm not sure if it makes a difference but I'm working locally and running MAMP. 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. Moving the initMap() function to scripts.js works fine. You can specify multiple pin locations and is a visual and useful. Moving the styles to style.css works fine. The Divi Map Module is an easy way to display an interactive Google map on your website. 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. ![]() Interestingly this line does appears in the head when I enqueue googlemaps: '/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 is a snippet from my functions.php: wp_register_script('googlemaps', '', array(''), '', true) There are also no errors in the developer console either. You can change true to false if you want it in the header. then we enqueue the script to be added in the footer. We then check if googlemapsapi function exists in case we forgot to include it. When I register/enqueue the script, it doesn't appear in the HTML source code when viewing the page. It simply checks if the current page has a locations field which would require a google map. Looks like the behaviour's changed in the latest version of WordPress - the above doesn't work (but I'll leave it for people on legacy versions).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. '&sensor=false' įor what it's worth, our (working) code is: wp_register_script('googlemaps', ''. I suspect your problem is that it's being double-encoded, as you already have &. I've got something similar in our code, and it's working fine (even encoded as &). I could of course just get the function to echo the HTML as a script tag, but I'd rather use the wp_enqueue_script system if possible. It is definitely not fine from Google's point of view. I saw a bug of this kind mentioned in the WordPress trac system: but it was dismissed as invalid, and the admin responding to the request showed somehow that the "&" approach was fine. However, I want my code to run the query that produces the GeoJSON data, and I know how to do that in php. Im using Xampp to load Apache and view files on my browser. When I type it directly into browser address bar with "&sensor=false" at the end, it loads fine. html the map shows up just fine, and it shows the data I want to see (a Linestring). This actually makes the Google server reject the request. WordPress is escaping the "&" to "&". Wp_enqueue_script('google-maps', $gmaps_url, NULL, NULL) $key = get_option('google_maps_api_key') The actual API key is configured in an options page I'm trying to load the Google Maps API using the following syntax: add_action('admin_enqueue_scripts', 'load_google_maps') ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |