wpgmp_infowindow_post_message - WP Maps Pro

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

wpgmp_infowindow_post_message

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.

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.