location Archives - Page 2 of 2 - WP Maps Pro

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

Hook Category: location

This hook in the WP Maps Pro plugin allows developers to customize the infowindow message for posts shown as locations on a map. It is triggered when the infowindow message needs to be generated or altered, providing a chance to modify the output string.

Usage

Developers can implement this hook in their theme’s functions.php file or in a custom plugin. It’s beneficial for altering the content displayed in map infowindows according to specific conditions or requirements. Ensure to return a string when using this hook.

Example 1

Change the infowindow message to include a custom field value from the post.

add_filter('wpgmp_infowindow_post_message', 'custom_infowindow_message', 10, 2);
function custom_infowindow_message($infowindow_geotags_setting, $map) {
    $custom_field_value = get_post_meta(get_the_ID(), 'custom_field_key', true);
    return $infowindow_geotags_setting . '<br>' . esc_html($custom_field_value);
}

Example 2

Modify the infowindow message to append a “Read More” link to the post.

add_filter('wpgmp_infowindow_post_message', 'append_read_more_link', 10, 2);
function append_read_more_link($infowindow_geotags_setting, $map) {
    $post_url = get_permalink(get_the_ID());
    return $infowindow_geotags_setting . '<br><a href="' . esc_url($post_url) . '">Read More</a>';
}

Example 3

Add an image from the post’s featured image to the infowindow message.

add_filter('wpgmp_infowindow_post_message', 'add_featured_image_to_infowindow', 10, 2);
function add_featured_image_to_infowindow($infowindow_geotags_setting, $map) {
    if (has_post_thumbnail()) {
        $image_url = get_the_post_thumbnail_url(get_the_ID(), 'thumbnail');
        return '<img src="' . esc_url($image_url) . '" alt="' . esc_attr(get_the_title()) . '">' . $infowindow_geotags_setting;
    }
    return $infowindow_geotags_setting;
}

Tip: Always sanitize and validate data when modifying the infowindow message to prevent security vulnerabilities, such as XSS attacks. Use functions like esc_html() and esc_url() to ensure data is safe for output.

The wpgmp_infowindow_message hook in WP Maps Pro allows developers to customize the content of the infowindow message dynamically. This hook is triggered when the infowindow message is being prepared for display, enabling developers to modify the message string using custom logic.

Usage

Developers can implement this hook by adding it to their theme’s functions.php file or in a custom plugin. It provides a way to alter the displayed infowindow message by applying custom filters, making it highly versatile for different use cases such as localization, adding dynamic content, or styling modifications.

Example 1

Description of the first use-case: Adding a prefix to the infowindow message to indicate special offers.

add_filter('wpgmp_infowindow_message', 'add_special_offer_prefix');
function add_special_offer_prefix($message) {
    return 'Special Offer: ' . $message;
}

Example 2

Description of the second use-case: Translating the infowindow message based on the user’s language preference.

add_filter('wpgmp_infowindow_message', 'translate_infowindow_message');
function translate_infowindow_message($message) {
    $translated_message = __('Your translation logic here', 'textdomain');
    return $translated_message;
}

Example 3

Description of the third use-case: Adding shortcode support to infowindow messages to include dynamic content.

add_filter('wpgmp_infowindow_message', 'do_shortcode_infowindow_message');
function do_shortcode_infowindow_message($message) {
    return do_shortcode($message);
}

Tip: Always validate and sanitize the data being passed through hooks to prevent security vulnerabilities such as XSS attacks.

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.