Load Google Maps Only After Cookie Consent (GDPR-Compliant)
Under the EU’s GDPR, you should not load third‑party scripts that collect personal data (like the visitor’s IP via the Google Maps API) before the user has given consent. WP MAPS PRO supports a consent-first flow so maps and their scripts load only after the visitor accepts cookies.
What’s the Issue?
Google Maps loads via the Google Maps JavaScript API. When this script is requested, the visitor’s IP address is sent to Google. Without prior consent, this can violate GDPR. The solution is to hold back the Maps scripts until the user accepts cookies.
Steps
Step 1: Go to WP MAPS PRO → Settings and enable Cookies Acceptance. Once enabled, the Google Maps API and maps will load after the visitor accepts cookies.
Step 2: Show a cookie consent banner. We recommend Cookie Notice by dFactory,
which is simple and flexible.
Step 3: (Optional, for custom consent plugins) Use the
wpgmp_accept_cookies
hook to tell WP MAPS PRO when to load scripts. This lets you integrate with
any GDPR/cookie plugin. Below is an example for the “Cookie Notice by dFactory” plugin.
Code Example: Verify Consent Before Loading Maps
Add this snippet to a site-specific plugin or your (child) theme’s functions.php
:
// Let WP MAPS PRO know if cookies were accepted.
// Example for "Cookie Notice by dFactory" plugin.
add_filter('wpgmp_accept_cookies', function ($accepted) {
// If Cookie Notice is active, use its helper.
if (function_exists('cn_cookies_accepted')) {
return cn_cookies_accepted(); // true when user has accepted cookies
}
// Fallback to whatever WP MAPS PRO passed in.
return $accepted;
});
Reference gist:
Verify Cookies Consent Before Showing the Google Maps
Tips
- If you use a different consent plugin, adapt the filter to call that plugin’s “consent accepted” function.
- After enabling consent mode, clear any caching/optimization (page cache, CDN, JS defer) so the change takes effect.
- Consider displaying a placeholder box (e.g., “Map will load after cookies are accepted”) for better UX.
Need Help?
Questions or custom integrations for GDPR? Email us at support@flippercode.com or open a ticket via our
Support Center.
Related Tutorials:
- Integrate iubenda with WP Maps Pro
- How to Integrate Borlabs Cookie with WP Maps Pro
- Integrating CookieYes with WP Maps Pro
- Integrating Cookie Notice & Compliance Plugin
- Load Google Maps Only After Cookie Consent (GDPR Compliant Setup)