wpgmp_post_placeholder - WP Maps Pro

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

wpgmp_post_placeholder

This hook in WP Maps Pro enables developers to customize the data displayed in the infowindow or the listing below the map by modifying the post’s data at runtime.

Usage

Developers can implement this hook in their theme’s functions.php file or through a custom plugin to alter how post data is presented on maps. It provides flexibility for customizing map displays to better fit the website’s requirements.

Example 1

Modify the post title and add a custom prefix to it for display in the infowindow.

add_filter('wpgmp_post_placeholder', 'custom_post_title_prefix', 10, 3);
function custom_post_title_prefix($replace_data, $post_id, $map) {
    $replace_data['post_title'] = 'Map Post: ' . $replace_data['post_title'];
    return $replace_data;
}

Example 2

Include a custom field value in the post excerpt if it exists.

add_filter('wpgmp_post_placeholder', 'add_custom_field_to_excerpt', 10, 3);
function add_custom_field_to_excerpt($replace_data, $post_id, $map) {
    $custom_field_value = get_post_meta($post_id, 'custom_field_key', true);
    if ($custom_field_value) {
        $replace_data['post_excerpt'] .= ' - ' . $custom_field_value;
    }
    return $replace_data;
}

Example 3

Change the marker image based on the post category.

add_filter('wpgmp_post_placeholder', 'custom_marker_image_by_category', 10, 3);
function custom_marker_image_by_category($replace_data, $post_id, $map) {
    if (has_category('special-category', $post_id)) {
        $replace_data['marker_image'] = 'http://example.com/path/to/special-marker.png';
    }
    return $replace_data;
}

Remember to validate and sanitize any data used in hook implementations to ensure security and stability of your WordPress site.

Install Plugin Now!

Buy this plugin exclusively on CodeCanyon! You’ll get free updates, full support, and if you’re not satisfied, we’ve got you covered with a 30-day money-back guarantee.