ACF Pro & Google Maps

Hello,

I am having a difficult time getting the ACF Pro Google Maps to work on the front end.

http://svcta.lainternet.biz/directory/grand-vista-hotel/stay/

The maps work fine in the Dashboard.

I can see in the console that my website is loading the Google Maps JS twice. Once from the ACF Pro code I added to the Functions file. The other instance I think is coming from X Theme. I am not using any X Theme Google Maps in this project.

Question - How do I fix the “js:122 You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors.” error?

I am hopeful that fixing this error will get my maps working.

Code in my Functions File

// ACF Google Maps Set API Key & Register Maps JS
// =============================================================================

function my_acf_init() {
acf_update_setting('google_api_key', 'AIzaSyCUMsQuFOe8S0qOd1OXFtUMd5raEkgUfkA');
}
add_action('acf/init', 'my_acf_init');


function acf_custom_scripts() {
wp_register_script('google_maps_js_external', '//maps.googleapis.com/maps/api/js?key=AIzaSyCUMsQuFOe8S0qOd1OXFtUMd5raEkgUfkA', array(),'3', true);
wp_enqueue_script('google_maps_js_external');
wp_register_script('google_maps_js_internal', get_stylesheet_directory_uri() . '/framework/js/google_maps_acf.js', array('jquery'),'0.1', true);
wp_enqueue_script('google_maps_js_internal');
}
add_action( 'wp_enqueue_scripts', 'acf_custom_scripts' );

The code in google_maps_acf.js comes from ACF Pro Documentation

Please note that the Maps were working fine a few months ago when I originally coded it.

Thanks,

Micah

Hey @websperations,

The Google Maps API being loaded is coming from UberMenu. Please uncheck Load Google Maps API in Appearance > UberMenu > General Settings > Google Maps.

That should resolve the double API error:

You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors.

Hope that helps.

Thank you so much for that!!!

My maps are working again and my console is error free :slight_smile:

Micah

You’re welcome, Micah. Glad we could help.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.