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
Description of the first use-case: Adding a prefix to the infowindow message to indicate special offers.
add_filter('wpgmp_infowindow_post_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_post_message', 'translate_infowindow_message'); function translate_infowindow_message($message) { $translated_message = '<div class="fc-infobox-root editable"><div class="fc-infobox"><div class="fc-infobox-body">'.__('Your translation logic here', 'textdomain').'</div></div></div>'; 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_post_message', 'do_shortcode_infowindow_message'); function do_shortcode_infowindow_message($message) { return do_shortcode($message); }
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.