wpgmp_openstreet_style - WP Maps Pro

15000+ live websites are using this google maps wordpress plugin.

wpgmp_openstreet_style

This hook allows developers to customize the map type of OpenStreetMap in the WP Maps Pro plugin. It is triggered when the map is being rendered, enabling changes to the tile sources for OpenStreetMap.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin to alter the available map styles. This can be useful for adding new map styles or modifying existing ones to suit specific needs.

Example 1

Add a custom map style to the list of OpenStreetMap styles.

add_filter('wpgmp_openstreet_style', 'add_custom_map_style');
function add_custom_map_style($openstreet_styles) {
    $openstreet_styles['CustomMap'] = 'https://custom.tile.server/{z}/{x}/{y}.png';
    return $openstreet_styles;
}

Example 2

Modify the URL of an existing map style to point to a different tile server.

add_filter('wpgmp_openstreet_style', 'modify_map_style_url');
function modify_map_style_url($openstreet_styles) {
    if (isset($openstreet_styles['OpenStreetMap.Mapnik'])) {
        $openstreet_styles['OpenStreetMap.Mapnik'] = 'https://another.tile.server/{z}/{x}/{y}.png';
    }
    return $openstreet_styles;
}

Example 3

Remove a specific map style from the available options.

add_filter('wpgmp_openstreet_style', 'remove_map_style');
function remove_map_style($openstreet_styles) {
    unset($openstreet_styles['OpenStreetMap.BZH']);
    return $openstreet_styles;
}

Tip: Always validate and sanitize any external URLs added via this hook to ensure they are secure and trustworthy, preventing potential security vulnerabilities.

Install Plugin Now!

WP MAPS PRO helps you create dynamic, customizable maps using Google Maps or Leaflet — no coding required. Includes free updates, premium support, and a 30-day money-back guarantee.