google maps api script enqueue handle

Home Forums Calendar Products Events Calendar PRO google maps api script enqueue handle

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #967940
    Susan Daniero
    Participant

    Howdy,

    I’ve got a site using events calendar pro v. 3.9.3. The site is also using google maps api to display a map in the footer on all pages.

    I get an error: “You have included the Google Maps API multiple times on this page. This may cause unexpected errors.”

    What I end up doing is overloading the tribe_events_google_maps_api queue so that it is queued regardless of which page I’m on.

    My issue is that I would have to use “tribe-gmaps” on some pages and “tribe_events_google_maps_api” on other pages to call the same script.

    First, is there any reason why you can’t just use tribe_events_google_maps_api instead of “tribe-gmaps” in events pro?

    Second, do you have a handy set of if statements that I can use during the wp_enqueue_scripts to select either tribe-gmaps or tribe_events_google_maps_api to overload?

    #968093
    Nico
    Member

    Hi Susan,

    Thanks for hitting the forums. Taking a look at what you described, I’m not sure why you are using ‘tribe-gmaps’ at all. Pasting this snippet in your ‘functions.php’ should do the trick:


    add_action( 'wp_enqueue_scripts', 'tribe_always_include_gmaps_api' );
    function tribe_always_include_gmaps_api(){
    if ( !wp_script_is( 'tribe_events_google_maps_api', 'queue') ){
    $url = apply_filters( 'tribe_events_google_maps_api', '//maps.googleapis.com/maps/api/js' );
    wp_enqueue_script( 'tribe_events_google_maps_api', $url, array(), false, true );
    }
    }

    This is working for me with latest version of The Events Calendar (3.9.3) and Event Calendar PRO (3.9.3) installed. Can you try this on your end?

    Please let me know how this goes,
    Best,
    Nico

    #968183
    Susan Daniero
    Participant

    Hi Nico,

    I have included this action snippet in my functions files, and with a small modification I believe I have the error resolved:

    (!wp_script_is( ‘tribe_events_google_maps_api’, ‘queue’)) && (!wp_script_is( ‘tribe-gmaps’, ‘queue’)) )

    As to why I am looking at ‘tribe-gmaps’, I haven’t looked through much of the code for event calendar pro, but that was the only enqueue I found for the gmaps api (in Tribe_PRO_Template_Factory::asset_package(), in my 3.9.3 it is l.63-71), so I changed the hook to match tribe_events_google_maps_api, and this resolved the problem, at least as far as I could test.

    I’m open to the idea that the problem is in the theme, but I haven’t looked around in events pro enough to know what the real issues is, but it looks like the TribeEventsGeoLoc calls the asset_package when it does geolocation-based filtering, and this pulls in the maps api, but using a different handle.

    #968186
    Susan Daniero
    Participant

    Re-reading my posting, I think that this statement is unclear:

    “so I changed the hook to match tribe_events_google_maps_api, and this resolved the problem, at least as far as I could test.”

    In testing, I modified the plugin code, but ultimately I’m using the unmodified code with the additional wp_script_is logic.

    #968203
    Nico
    Member

    Susan,

    Great catch indeed. Glad you could solve this 🙂

    I’ll go ahead and close this topic – but please don’t hesitate to create new topics if you need help with anything else.

    Have a great day,
    Nico

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘google maps api script enqueue handle’ is closed to new replies.