wpgmp_mapbox_style - WP Maps Pro

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

wpgmp_mapbox_style

The wpgmp_mapbox_style hook in the WP Maps Pro plugin allows developers to customize the map type and style when using Mapbox. This hook is particularly useful for modifying the appearance of maps by changing the default mapbox style to one that best suits the application’s or website’s design needs.

Usage

Developers can implement this hook within their theme’s functions.php file or within a custom plugin. This hook is used to filter the available mapbox styles and can be applied whenever there is a need to modify the map’s visual style dynamically.

Example 1

Change the default map style to ‘light’.

add_filter('wpgmp_mapbox_style', 'custom_mapbox_style');
function custom_mapbox_style($map_box_styles) {
    $map_box_styles = 'light-v10';
    return $map_box_styles;
}

Example 2

Allow only ‘outdoors’ and ‘satellite’ styles to be selectable.

add_filter('wpgmp_mapbox_style', 'restrict_mapbox_styles');
function restrict_mapbox_styles($map_box_styles) {
    return array_intersect_key($map_box_styles, array_flip(['outdoors-v11', 'satellite-v9']));
}

Example 3

Change the default style to ‘dark’ only if the current user is an administrator.

add_filter('wpgmp_mapbox_style', 'admin_only_dark_style');
function admin_only_dark_style($map_box_styles) {
    if (current_user_can('administrator')) {
        $map_box_styles = 'dark-v10';
    }
    return $map_box_styles;
}

Tip: Always ensure that your modifications using this hook do not conflict with other map settings or styles, and test thoroughly to maintain a consistent user experience across different browsers and devices.

Install Plugin Now!

Buy this plugin exclusively on CodeCanyon! You’ll get free updates, full support, and if you’re not satisfied, we’ve got you covered with a 30-day money-back guarantee.