Title: Google Maps API multiple times fix?
Last modified: February 14, 2018

---

# Google Maps API multiple times fix?

 *  [deanljbirch](https://wordpress.org/support/users/deanljbirch/)
 * (@deanljbirch)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/google-maps-api-multiple-times-fix/)
 * **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)

 *  [HudsonValleyWebDesign](https://wordpress.org/support/users/jaycbrf/)
 * (@jaycbrf)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/google-maps-api-multiple-times-fix/#post-9974918)
 * 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](https://www.google.com/search?q=wordpress+conditional+enqueue)
 *  Thread Starter [deanljbirch](https://wordpress.org/support/users/deanljbirch/)
 * (@deanljbirch)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/google-maps-api-multiple-times-fix/#post-10018738)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [deanljbirch](https://wordpress.org/support/users/deanljbirch/)
 * Last activity: [8 years, 3 months ago](https://wordpress.org/support/topic/google-maps-api-multiple-times-fix/#post-10018738)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
