200,000+ live websites are using this google maps wordpress plugin.

Pricing
Pricing

wpgmp_featured_image

Filter by Topics

The wpgmp_featured_image hook in the WP Maps Pro plugin allows developers to customize the featured image URL of a post at runtime. It is triggered when the plugin is determining what image to use as the featured image for a specific post within a map context.

Usage

Developers can implement this hook to modify the URL of the featured image for posts displayed on a map. It can be particularly useful for dynamically changing images based on certain conditions or external data sources. This hook accepts three parameters: $post_featured_image (the current URL of the featured image), $post_id (the ID of the post), and $map_id (the ID of the map).

Example 1

Change the featured image URL for a specific post ID.

add_filter('wpgmp_featured_image', 'custom_post_featured_image', 10, 3);
function custom_post_featured_image($post_featured_image, $post_id, $map_id) {
    if ($post_id == 123) {
        $post_featured_image = '<div class="fc-feature-img"><img loading="lazy" decoding="async" alt="The Unlimited Sunrise" width="300" height="193" src="https://example.com/new-image.jpg" class="wp-post-image   wpgmp_featured_image"></div>';
    }
    return $post_featured_image;
}

Example 2

Use a different featured image for posts on a specific map.

add_filter('wpgmp_featured_image', 'map_specific_featured_image', 10, 3);
function map_specific_featured_image($post_featured_image, $post_id, $map_id) {
    if ($map_id == 456) {
        $post_featured_image = '<div class="fc-feature-img"><img loading="lazy" decoding="async" alt="The Unlimited Sunrise" width="300" height="193" src="https://example.com/new-image.jpg" class="wp-post-image   wpgmp_featured_image"></div>';
    }
    return $post_featured_image;
}

Example 3

Modify the featured image based on a custom field value.

add_filter('wpgmp_featured_image', 'custom_field_based_featured_image', 10, 3);
function custom_field_based_featured_image($post_featured_image, $post_id, $map_id) {
    $custom_image_url = get_post_meta($post_id, 'custom_image_url', true);
    if (!empty($custom_image_url)) {
        $post_featured_image = '<div class="fc-feature-img"><img loading="lazy" decoding="async" alt="The Unlimited Sunrise" width="300" height="193" src="'.$custom_image_url.'" class="wp-post-image   wpgmp_featured_image"></div>';
    }
    return $post_featured_image;
}

Always ensure that the URL you are using for the featured image is valid and accessible. Additionally, validate any data retrieved from external sources to prevent security vulnerabilities.