The ‘wpgmp_before_listing’ hook in the WP Maps Pro plugin allows developers to insert custom HTML before the listing container. This hook is triggered just before the map listing is rendered, providing an opportunity to modify or add content dynamically.
Usage
Developers can implement this hook in their theme’s functions.php file or within a custom plugin. It’s essential to ensure that any HTML inserted is correctly formatted and sanitized to prevent security vulnerabilities, such as XSS (Cross-Site Scripting).
Example 1
Adding a custom message before the listing.
add_action('wpgmp_before_listing', 'add_custom_message_before_listing', 10, 2); function add_custom_message_before_listing($html, $map) { echo '<p>Welcome to our map listings!</p>'; }
Example 2
Inserting a search form before the listing for better user navigation.
add_action('wpgmp_before_listing', 'insert_search_form_before_listing', 10, 2); function insert_search_form_before_listing($html, $map) { echo '<form method="get" action=""> <input type="text" name="search" placeholder="Search Listings"> <button type="submit">Search</button> </form>'; }
Example 3
Displaying map-related information dynamically before the listing.
add_action('wpgmp_before_listing', 'display_map_info', 10, 2); function display_map_info($html, $map) { echo '<div class="map-info"> <p>Map ID: ' . esc_html($map->id) . '</p> <p>Map Name: ' . esc_html($map->name) . '</p> </div>'; }
Tip: Always remember to validate and sanitize any user input or dynamic data to protect against potential security threats.