map Archives - Page 3 of 3 - WP Maps Pro

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

Hook Category: map

This hook in WP Maps Pro allows developers to add custom HTML or functionality directly after the map element’s div. It is triggered after the map has been rendered on the page.

Usage

Developers can implement this hook in their theme’s functions.php file or through a custom plugin. It is particularly useful for adding content or scripts that need to be positioned directly after the map. Understanding the parameters and ensuring compatibility with the rest of your code is crucial.

Example 1

Adding a custom message after the map to prompt users to take action.

    add_action('wpgmp_after_map', 'add_custom_message_after_map', 10, 2);
    function add_custom_message_after_map($map_id) {
        echo '<div class="custom-message">Explore the map to find interesting locations!</div>';
    }
    

Example 2

Injecting a custom script for tracking user interactions with the map.

    add_action('wpgmp_after_map', 'add_tracking_script_after_map', 10, 2);
    function add_tracking_script_after_map($map_id) {
        echo '<script>console.log("Map with ID ' . $map_id . ' has been displayed.");</script>';
    }
    

Example 3

Appending a button that links to additional resources related to the map content.

    add_action('wpgmp_after_map', 'add_resource_button_after_map', 10, 2);
    function add_resource_button_after_map($map_id) {
        echo '<a href="https://example.com/resources" class="resource-button">More Resources</a>';
    }
    

Tip: Always validate and sanitize any data that is output using this hook to prevent security vulnerabilities. Consider the impact of additional content on the user experience and page load times.

The wpgmp_map_lang hook in the WP Maps Pro plugin allows developers to customize the language setting of the map dynamically. It is particularly useful when you need to display the map in different languages based on user preferences or settings.

Usage

Developers can implement this hook in their theme’s functions.php file or within a custom plugin. By attaching a function to this hook, you can modify the language parameter of the map at runtime. It’s important to ensure the language code you set is supported by the map service you are utilizing.

Example 1

This example demonstrates how to change the map language to Spanish.

add_filter('wpgmp_map_lang', 'set_map_language_to_spanish');
function set_map_language_to_spanish($language) {
    return 'es';
}

Example 2

In this example, the map language is set based on a user’s profile setting.

add_filter('wpgmp_map_lang', 'customize_map_language_based_on_user');
function customize_map_language_based_on_user($language) {
    $user_language = get_user_meta(get_current_user_id(), 'preferred_language', true);
    return $user_language ? $user_language : 'en';
}

Example 3

Here, the map language is selected according to the site’s default language set in the settings.

add_filter('wpgmp_map_lang', 'set_map_language_to_site_default');
function set_map_language_to_site_default($language) {
    $site_language = get_option('WPLANG');
    return $site_language ? $site_language : 'en';
}

Tip: When using the wpgmp_map_lang hook, always validate the language code to ensure compatibility with the map service. Additionally, consider user experience and provide fallbacks when necessary.

This hook in the WP Maps Pro plugin allows developers to customize the street view settings of a map at runtime. It is particularly useful for modifying parameters like street control visibility, view orientation, and other street view options.

Usage

Developers can implement this hook in their theme’s functions.php file or within a custom plugin. It provides flexibility to adjust street view settings dynamically based on specific conditions or preferences. Practical tips include ensuring the map data object is correctly passed and verified for null or unexpected values.

Example 1

In this example, we customize the street view settings to disable the street view close button.

add_filter('wpgmp_map_streetview', 'custom_street_view_settings', 10, 2);
function custom_street_view_settings($map_data, $map) {
    $map_data['street_view']['street_view_close_button'] = false;
    return $map_data;
}

Example 2

This example demonstrates how to enable the links control in the street view settings.

add_filter('wpgmp_map_streetview', 'enable_links_control', 10, 2);
function enable_links_control($map_data, $map) {
    $map_data['street_view']['links_control'] = true;
    return $map_data;
}

Example 3

Here, the POV heading and pitch are adjusted to provide a specific view angle.

add_filter('wpgmp_map_streetview', 'adjust_pov_view', 10, 2);
function adjust_pov_view($map_data, $map) {
    $map_data['street_view']['pov_heading'] = '90';
    $map_data['street_view']['pov_pitch'] = '30';
    return $map_data;
}

Tip: Always validate and sanitize any data being modified to prevent potential security vulnerabilities or map display issues.

The wpgmp_map_styles hook in WP Maps Pro allows developers to alter the style of maps dynamically. This hook is particularly useful when you need to apply custom styles to the map, such as changing colors or visibility of map features, at runtime.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It is used to modify the map styles by accessing and changing the $map_data[‘styles’] parameter. The hook provides flexibility to apply different styles based on specific conditions or user preferences.

Example 1

This example demonstrates how to change the color of administrative features on the map.

add_filter('wpgmp_map_styles', 'custom_admin_color_style', 10, 2);

function custom_admin_color_style($styles, $map) {
    $styles[] = [
        "featureType" => "administrative",
        "elementType" => "all",
        "stylers" => [
            ["color" => "#0000ff", "visibility" => "on"]
        ]
    ];
    return $styles;
}

Example 2

In this example, we are setting the visibility of road features to ‘off’ to create a cleaner map layout.

add_filter('wpgmp_map_styles', 'hide_road_features', 10, 2);

function hide_road_features($styles, $map) {
    $styles[] = [
        "featureType" => "road",
        "elementType" => "all",
        "stylers" => [
            ["visibility" => "off"]
        ]
    ];
    return $styles;
}

Example 3

This example shows how to apply a grayscale effect to all map features for a minimalist design.

add_filter('wpgmp_map_styles', 'apply_grayscale_style', 10, 2);

function apply_grayscale_style($styles, $map) {
    $styles[] = [
        "featureType" => "all",
        "elementType" => "all",
        "stylers" => [
            ["saturation" => -100]
        ]
    ];
    return $styles;
}

Tip: Always test your map styles to ensure they enhance user experience without compromising map readability. Use the Google Maps Styling Wizard for previewing styles before applying them.

This hook allows developers to customize map settings at runtime in the WP Maps Pro plugin. It is triggered before displaying the map, providing an opportunity to modify the map’s configuration.

Usage

Developers can implement this hook within their theme’s functions.php file or a custom plugin. It provides a way to adjust map settings dynamically, such as changing the map’s center, zoom level, or appearance, based on specific conditions or requirements.

Example 1

Change the map’s zoom level to 5 before rendering the map.

add_filter('wpgmp_map_options', 'custom_map_zoom_level');
function custom_map_zoom_level($map_options) {
    $map_options['zoom'] = 5;
    return $map_options;
}

Example 2

Set the map type to SATELLITE for a different viewing experience.

add_filter('wpgmp_map_options', 'custom_map_type');
function custom_map_type($map_options) {
    $map_options['map_type_id'] = 'SATELLITE';
    return $map_options;
}

Example 3

Modify the center marker icon to a custom SVG image.

add_filter('wpgmp_map_options', 'custom_center_marker_icon');
function custom_center_marker_icon($map_options) {
    $map_options['center_marker_icon'] = 'data:image/svg+xml;charset=UTF-8,...'; // Custom SVG data
    return $map_options;
}

Tip: Always validate and sanitize any external data before using it to modify map options to ensure security and prevent potential vulnerabilities.

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.

This hook allows developers to modify the message displayed to users when map functionality requires cookies acceptance in the WP Maps Pro plugin. It is triggered when the plugin checks if cookies acceptance is mandatory.

Usage

Developers can implement this hook in their theme’s functions.php file or in a custom plugin. It enables modification of the no-map notice text, allowing you to provide a custom message to users. Ensure to use this custom hook to enhance user experience without compromising functionality.

Example 1

Customize the no-map notice to provide a more detailed explanation to users.

add_filter( 'wpgmp_nomap_notice', 'custom_no_map_notice', 10, 2 );
function custom_no_map_notice( $no_map_notice, $map_id ) {
    return 'To view the map, please accept cookies. This is important for loading map functionalities.';
}

Example 2

Change the message based on the map ID, providing specific instructions for different maps.

add_filter( 'wpgmp_nomap_notice', 'map_specific_notice', 10, 2 );
function map_specific_notice( $no_map_notice, $map_id ) {
    if ( $map_id == 42 ) {
        return 'Map 42 requires cookies to show local attractions. Please accept cookies.';
    }
    return $no_map_notice;
}

Example 3

Append a link to a cookie policy page in the no-map notice for user guidance.

add_filter( 'wpgmp_nomap_notice', 'notice_with_policy_link', 10, 2 );
function notice_with_policy_link( $no_map_notice, $map_id ) {
    $policy_url = site_url('/cookie-policy/');
    return $no_map_notice . ' <a href="' . $policy_url . '">Learn more about our cookie policy.</a>';
}

Tip: Always test your changes in a staging environment first to avoid disrupting the user experience on your live site. Ensure that your custom messages comply with legal standards and clearly communicate the necessity of accepting cookies.

This hook in WP Maps Pro allows developers to customize the functionality of map overlays at runtime. It is used to modify the overlay settings of a map, such as border color, width, height, font size, border width, and border style.

Usage

Developers can implement this hook in their theme’s functions.php file or in a custom plugin to modify the overlay settings of maps provided by the WP Maps Pro plugin. By using this hook, you can dynamically change how map overlays are displayed based on specific conditions or requirements.

Example 1

This example demonstrates how to change the border color of the map overlay to blue.

add_filter('wpgmp_map_overlays', 'customize_map_overlay_border_color', 10, 2);

function customize_map_overlay_border_color($overlay_settings, $map) {
    $overlay_settings['border_color'] = '#0000ff'; // Change border color to blue
    return $overlay_settings;
}

Example 2

In this example, the border style of the map overlay is changed to solid.

add_filter('wpgmp_map_overlays', 'customize_map_overlay_border_style', 10, 2);

function customize_map_overlay_border_style($overlay_settings, $map) {
    $overlay_settings['border_style'] = 'solid'; // Change border style to solid
    return $overlay_settings;
}

Example 3

This example shows how to increase the font size of the map overlay text.

add_filter('wpgmp_map_overlays', 'customize_map_overlay_font_size', 10, 2);

function customize_map_overlay_font_size($overlay_settings, $map) {
    $overlay_settings['font_size'] = '18'; // Increase font size
    return $overlay_settings;
}

Tip: Always validate and sanitize your inputs when modifying overlay settings to ensure the security and stability of your WordPress site.

This hook in WP Maps Pro allows developers to customize the map’s panning behavior at runtime. It is triggered when the map’s panning functionality is about to be processed, providing an opportunity to modify the default panning constraints.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin to adjust the panning limits of a map. This is particularly useful when specific control over the map’s navigable area is needed, such as restricting user movement to a particular region.

Example 1

Modify the map to restrict panning to a more narrow area.

add_filter('wpgmp_map_panning', 'custom_map_panning_restrictions', 10, 2);
function custom_map_panning_restrictions($panning_control, $map) {
    $panning_control['from_latitude'] = '10.0';
    $panning_control['from_longitude'] = '10.0';
    $panning_control['to_latitude'] = '40.0';
    $panning_control['to_longitude'] = '40.0';
    return $panning_control;
}

Example 2

Allow the map to pan freely without any restrictions.

add_filter('wpgmp_map_panning', 'remove_map_panning_restrictions', 10, 2);
function remove_map_panning_restrictions($panning_control, $map) {
    return array(); // Empty array to remove all panning limits.
}

Example 3

Set custom panning limits based on conditions, such as user roles.

add_filter('wpgmp_map_panning', 'conditional_map_panning', 10, 2);
function conditional_map_panning($panning_control, $map) {
    if(current_user_can('administrator')) {
        // Allow admin users more freedom in panning
        $panning_control['from_latitude'] = '0.0';
        $panning_control['to_latitude'] = '50.0';
    } else {
        // Restrict panning for other users
        $panning_control['from_latitude'] = '20.0';
        $panning_control['to_latitude'] = '30.0';
    }
    return $panning_control;
}

Tip: Always validate user inputs and conditions when modifying map behavior with hooks to ensure a secure and user-friendly experience.

This hook in the WP Maps Pro plugin allows developers to customize map routes by modifying route data before it is rendered. It is triggered when routes are assigned or unassigned to a map.

Usage

Developers can implement this hook in their WordPress theme’s functions.php file or within a custom plugin to adjust route properties such as color, weight, and travel mode. This is particularly useful for dynamically configuring map routes based on specific conditions or settings.

Example 1

This example changes the stroke color of all routes to red.

add_filter('wpgmp_map_routes', 'customize_route_colors', 10, 2);
function customize_route_colors($routes, $map) {
    foreach ($routes as &$route) {
        $route['route_stroke_color'] = '#FF0000'; // Change stroke color to red
    }
    return $routes;
}

Example 2

In this example, the travel mode for all routes is set to ‘BICYCLING’.

add_filter('wpgmp_map_routes', 'set_travel_mode_to_bicycling', 10, 2);
function set_travel_mode_to_bicycling($routes, $map) {
    foreach ($routes as &$route) {
        $route['route_travel_mode'] = 'BICYCLING'; // Change travel mode to bicycling
    }
    return $routes;
}

Example 3

This example adds a condition to only optimize waypoints for routes with the title “UVA to Microsoft HQ”.

add_filter('wpgmp_map_routes', 'optimize_uva_to_microsoft_route', 10, 2);
function optimize_uva_to_microsoft_route($routes, $map) {
    foreach ($routes as &$route) {
        if ($route['route_title'] === 'UVA to Microsoft HQ') {
            $route['route_optimize_waypoints'] = true; // Optimize waypoints for this route
        }
    }
    return $routes;
}

Remember to always validate and sanitize any data manipulated through hooks to ensure security and prevent potential 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.