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
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?