• Hello!

    I’m using the plugins bp xprofile location and ACF google map, and it creates a conflict with js being loaded more than once (You have included the Google Maps API multiple times on this page. This may cause unexpected errors.).

    The problem is that I can’t manage to disable one script and have only one being loaded.
    When adding the function to load the script for the ACF google map, I tried specifying to load the script only on specific page/template where I need it, it does cancel the js error but then the map doesn’t render (even though it is on the template specified).

    function custom_add_scripts() {
    
          
        wp_register_script ( 'google-map', 'https://maps.googleapis.com/maps/api/js?key=my_key_here',array(), '3', true);
        wp_register_script ( 'google-map-init', get_stylesheet_directory_uri() . '/js/google-maps.js', array('google-map', 'jquery'), '0.1', true );
    
    	 if ( is_page_template('custom-page.php') ) {
    	wp_enqueue_script ( 'google-map');
    	wp_enqueue_script ( 'google-map-init');
    }
    }
     
    add_action( 'wp_enqueue_scripts', 'custom_add_scripts' );
    

    I’ve also tried modifying the plugin’s file to load the script I registered above, to use the same, but that didn’t work either.
    I can follow tutorials but my general understanding is quite limited.

    Would anyone know how I can stop one of the script to load and have both plugins use the same?

    Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Example page?

    Somewhat aside, have you added the new API key required for ACF Google Maps to work?

    I recall having this issue before and resolving it, but can’t for the life of me remember the project.

    Your code above though appears to be purposely loading both versions.

    wp_register_script ( 'google-map', 'https://maps.googleapis.com/maps/api/js?key=my_key_here',array(), '3', true);
    wp_register_script ( 'google-map-init', get_stylesheet_directory_uri() . '/js/google-maps.js', array('google-map', 'jquery'), '0.1', true );

    Try just registering and loading the first one, and replacing my_key_here with your actual Maps API key.

    Thread Starter kida18

    (@kida18)

    Hey Clicknathan,

    Thanks for the suggestions.
    Yes I had replaced the my_key_here to the code, have just removed it before posting here.

    I’d already tried what you suggested (removing one of the two versions), and the map from the ACF field renders only when they are both added. If I remove one of the two, the map displays on the back-end but not on the front-end. I’ve tried to enqueue them directly, without registering them, but that didn’t work either.

    I can’t show you an example page right now unfortunately

    Thread Starter kida18

    (@kida18)

    Anyone? I haven’t managed to find a solution.
    How would one do to use the google maps API in several plugins without having a conflict?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Google Maps API conflict’ is closed to new replies.