The wpgmp_shortcode_attributes hook in the WP Maps Pro plugin allows developers to customize the attributes for the [put_wpgmp]
shortcode. It is triggered when the shortcode is processed, enabling the addition or removal of attributes dynamically.
Usage
Developers can implement this hook in their theme’s functions.php
file or in a custom plugin. The hook provides the flexibility to modify the attributes of a map displayed using the shortcode, which can be particularly useful for tailoring the map’s behavior or appearance based on certain conditions.
Example 1
This example demonstrates how to change the limit
attribute to show only 5 locations.
add_filter('wpgmp_shortcode_attributes', 'modify_map_limit'); function modify_map_limit($options) { $options['limit'] = 5; return $options; }
Example 2
In this example, we add a new attribute to display maps from a specific category named “restaurants”.
add_filter('wpgmp_shortcode_attributes', 'add_category_filter'); function add_category_filter($options) { $options['category'] = 'restaurants'; return $options; }
Example 3
This example shows how to remove the show_all_locations
attribute to prevent showing all locations by default.
add_filter('wpgmp_shortcode_attributes', 'remove_show_all_locations'); function remove_show_all_locations($options) { unset($options['show_all_locations']); return $options; }
Remember to always validate and sanitize input data when modifying shortcode attributes to ensure security and prevent potential vulnerabilities.