• Hey there,

    A website I’m currently developing requires 3 specific apps;

    • Sabai Directory
    • Events Calendar Pro
    • WP Job Manager (Geo)

    However, each of these plugins require a Google Maps API key.

    In turn, they each insert the Google Maps API script into WP_Head. This causes countless errors which render them useless.

    If there any way I can fix this completely? Even if I could specify the script to load on specific pages? Unsure how I would be able to achieve this for the events calendar as the page doesn’t get added to my page list in the dashboard.

    Deano.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can use conditional tags in the functions.php to load different bits of code depending on what page is loaded.

    https://www.google.com/search?q=wordpress+conditional+enqueue

    Thread Starter deanljbirch

    (@deanljbirch)

    I have 3 plugins all of which require Google Maps API to load up (separate keys are used on each plugin too).

    However these are loading on each page causing errors.

    Now, I have decided to conditionally enqueue each script like so;

    add_action('wp_enqueue_scripts', 'add_script_function');
    function add_script_function() {
        if (is_page(2393)) {
            wp_enqueue_script('SERVICESGMAPI', 'https://maps.googleapis.com/maps/api/js?key=KEYHIDDEN&libraries=places&language=en-GB');
            );
        }
    }
    add_action('wp_enqueue_scripts', 'add_script_function');
    function add_script_function() {
        if (is_page(vacancies)) {
            wp_enqueue_script('VACANCIESGMAPI', 'https://maps.googleapis.com/maps/api/js?key=KEYHIDDEN&libraries=places&language=en-GB');
            );
        }
    }
    add_action('wp_enqueue_scripts', 'add_script_function');
    function add_script_function() {
        if (is_page(events)) {
            wp_enqueue_script('EVENTSGMAPI', 'https://maps.googleapis.com/maps/api/js?key=KEYHIDDEN&libraries=places&language=en-GB');
            );
        }
    }

    BUT, with the events page, each event is permalinked like so;

    mydomain.tld/event/marathon
    mydomain.tld/event/meeting
    mydomain.tld/event/EVENTNAME
    So the code above (3rd part) will load the script on mydomain.tld/events, how can I set it to work on the event/* pages?

    Also, the scripts are being loaded via the plugins, if I change that via editting the plugins, changes will revert on updates. Any advice?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Google Maps API multiple times fix?’ is closed to new replies.