Custom Google Map Style Not Applying in WordPress Elementor? Here’s the Fix

Troubleshooting Custom Google Map Styles in Elementor

It’s a common issue for custom Google Map styles not to apply correctly in Elementor. This guide will walk you through a series of steps to identify and fix the problem.

1. Verify Your Google Maps API Key Setup

The most frequent cause of map styling issues is an improperly configured API key.

  • Enable Necessary APIs: Ensure you have the following APIs enabled for your project in the Google Cloud Console:
    • Maps JavaScript API: Essential for displaying the map on your site.
    • Geocoding API: Needed to convert addresses into geographic coordinates.
  • Check Billing Information: Google Maps Platform usage is not entirely free. You must have a valid billing account associated with your project, even if your usage falls within the free tier.
  • API Key Restrictions: For security, you should restrict your API key. However, incorrect restrictions can prevent the map from loading.
    • HTTP Referrers: If you’ve restricted the key to specific websites, double-check that you’ve entered your domain name correctly. Use the format *.yourdomain.com/* to allow all pages on your site.
    • IP Addresses: If you’ve restricted by IP address, make sure your server’s IP is correctly listed.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Custom Styled Google Map</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        /* Apply Inter font to the body */
        body {
            font-family: 'Inter', sans-serif;
        }
        /* Ensure the map container takes up full height */
        #map {
            height: 100vh; /* Full viewport height */
            width: 100%;  /* Full width */
        }
    </style>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
    <div class="container mx-auto p-4 max-w-4xl bg-white rounded-lg shadow-xl">
        <h1 class="text-3xl font-bold text-center text-gray-800 mb-6">Custom Styled Google Map Example</h1>
        <p class="text-gray-600 text-center mb-8">
            This example demonstrates how to load a Google Map with custom styles applied directly via JavaScript.
            Remember to replace <code class="bg-gray-200 p-1 rounded">YOUR_API_KEY</code> with your actual Google Maps API Key.
        </p>
        <div id="map" class="rounded-lg border border-gray-300"></div>
    </div>

    <script>
        // Function to initialize the map
        function initMap() {
            // Define the custom map styles
            // This is a 'silver' style example. You can generate more complex styles
            // using tools like Snazzy Maps (snazzymaps.com).
            const customMapStyle = [
                {
                    "elementType": "geometry",
                    "stylers": [
                        { "color": "#f5f5f5" }
                    ]
                },
                {
                    "elementType": "labels.icon",
                    "stylers": [
                        { "visibility": "off" }
                    ]
                },
                {
                    "elementType": "labels.text.fill",
                    "stylers": [
                        { "color": "#616161" }
                    ]
                },
                {
                    "elementType": "labels.text.stroke",
                    "stylers": [
                        { "color": "#f5f5f5" }
                    ]
                },
                {
                    "featureType": "administrative.land_parcel",
                    "elementType": "labels.text.fill",
                    "stylers": [
                        { "color": "#bdbdbd" }
                    ]
                },
                {
                    "featureType": "poi",
                    "elementType": "geometry",
                    "stylers": [
                        { "color": "#eeeeee" }
                    ]
                },
                {
                    "featureType": "poi",
                    "elementType": "labels.text.fill",
                    "stylers": [
                        { "color": "#757575" }
                    ]
                },
                {
                    "featureType": "poi.park",
                    "elementType": "geometry",
                    "stylers": [
                        { "color": "#e5e5e5" }
                    ]
                },
                {
                    "featureType": "poi.park",
                    "elementType": "labels.text.fill",
                    "stylers": [
                        { "color": "#9e9e9e" }
                    ]
                },
                {
                    "featureType": "road",
                    "elementType": "geometry",
                    "stylers": [
                        { "color": "#ffffff" }
                    ]
                },
                {
                    "featureType": "road.arterial",
                    "elementType": "labels.text.fill",
                    "stylers": [
                        { "color": "#757575" }
                    ]
                },
                {
                    "featureType": "road.highway",
                    "elementType": "geometry",
                    "stylers": [
                        { "color": "#dadada" }
                    ]
                },
                {
                    "featureType": "road.highway",
                    "elementType": "labels.text.fill",
                    "stylers": [
                        { "color": "#616161" }
                    ]
                },
                {
                    "featureType": "road.local",
                    "elementType": "labels.text.fill",
                    "stylers": [
                        { "color": "#9e9e9e" }
                    ]
                },
                {
                    "featureType": "transit.line",
                    "elementType": "geometry",
                    "stylers": [
                        { "color": "#e5e5e5" }
                    ]
                },
                {
                    "featureType": "transit.station",
                    "elementType": "geometry",
                    "stylers": [
                        { "color": "#eeeeee" }
                    ]
                },
                {
                    "featureType": "water",
                    "elementType": "geometry",
                    "stylers": [
                        { "color": "#c9c9c9" }
                    ]
                },
                {
                    "featureType": "water",
                    "elementType": "labels.text.fill",
                    "stylers": [
                        { "color": "#9e9e9e" }
                    ]
                }
            ];

            // Set the center coordinates for the map (e.g., New York City)
            const mapCenter = { lat: 40.7128, lng: -74.0060 }; // New York City coordinates

            // Create a new map instance
            const map = new google.maps.Map(document.getElementById("map"), {
                zoom: 12, // Initial zoom level
                center: mapCenter, // Center of the map
                styles: customMapStyle, // Apply the custom styles here
                disableDefaultUI: false, // You can set this to true to remove default UI controls
            });

            // Add a marker to the map
            new google.maps.Marker({
                position: mapCenter,
                map: map,
                title: "Our Location" // Title for the marker
            });
        }

        // Load the Google Maps API script dynamically
        // Replace 'YOUR_API_KEY' with your actual Google Maps API Key
        const apiKey = "YOUR_API_KEY"; // IMPORTANT: Replace with your actual API key
        const script = document.createElement("script");
        script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=initMap`;
        script.async = true;
        script.defer = true;
        document.head.appendChild(script);
    </script>
</body>
</html>

2. Validate Your Custom Style JSON

The code you use for styling the map must be valid JSON.

  • Check for Syntax Errors: Even a small error, like a missing comma or bracket, will break the styling.
  • Use a JSON Validator: Copy your custom style code and paste it into an online validator like JSONLint to quickly find any syntax errors.
  • Snazzy Maps: If you’re using styles from a site like Snazzy Maps, ensure you’ve copied the entire JSON array correctly.

3. Review Elementor Widget Settings

  • Correctly Paste the JSON: In the Elementor Google Maps widget, under the “Style” tab, ensure you’ve pasted your custom JSON code into the “Custom Style” field.
  • Clear Widget-Specific Caching: Sometimes, Elementor’s caching can cause delays in seeing changes. Try saving your changes, clearing your site’s cache, and then viewing the page in an incognito/private browser window.

4. Check for Theme and Plugin Conflicts

Another common culprit is a conflict with your WordPress theme or another plugin.

  • Temporarily Switch Themes: Switch to a default WordPress theme (like “Twenty Twenty-Four”). If the map style appears, your theme is the source of the conflict.
  • Deactivate Other Plugins: Deactivate all plugins except for Elementor and Elementor Pro. If the map style works, reactivate your plugins one by one to find the one causing the issue.

5. Clear Caches

  • Browser Cache: Clear your browser’s cache and cookies to ensure you’re not viewing a cached, unstyled version of the map.
  • WordPress Caching Plugins: If you use a caching plugin (e.g., WP Rocket, W3 Total Cache), clear the cache.
  • Server-Side Caching: Your hosting provider might have server-level caching. Check your hosting control panel for options to clear the cache.

6. Regenerate Elementor’s CSS

Elementor creates CSS files for your pages. Sometimes, these files can become outdated.

  1. Go to your WordPress Dashboard.
  2. Navigate to Elementor > Tools.
  3. Click the Regenerate Files & Data button.

7. Use the Browser’s Developer Console

If you’re still having trouble, your browser’s developer console can provide specific error messages.

  1. Right-click on your webpage and select “Inspect” or “Inspect Element.”
  2. Click on the “Console” tab.
  3. Look for any errors related to the Google Maps API. These messages can often point you to the exact problem (e.g., “ApiNotActivatedMapError,” “InvalidKeyMapError”).

By systematically working through these steps, you should be able to identify and resolve the issue with your custom Google Map style.

Related Posts


How to detect YouTube iframe tag in a specific WordPress post

Detecting YouTube Iframes in WordPress Posts This document outlines two primary methods for detectin...

How to Prevent Category Pages from Highlighting the Blog Menu in WordPress

When category archive pages automatically highlight your blog menu item in WordPress, it’s bec...

Customize WordPress User Approval Emails Without Plugins (Step-by-Step Guide)

Customizing WordPress user approval emails without plugins involves using WordPress’s built-in...

Unable To Update Order Meta in Woocomerce?

Having trouble updating order meta in WooCommerce?  This is a common issue that can stem from vario...

Recent Posts