location Archives - WP Maps Pro

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

Hook Category: location

The wpgmp_default_marker_icon hook in WP Maps Pro allows developers to customize the URL of the default marker icon used in maps. This hook is triggered when the default marker icon URL is being retrieved, providing an opportunity to modify it at runtime.

Usage

Developers can implement this hook in their theme’s functions.php file or through a custom plugin. It is particularly useful when you want to change the appearance of map markers globally without altering the plugin’s core files. Make sure to define a valid and accessible URL for the marker icon.

Example 1

Changing the default marker icon to a custom image hosted on your server.

add_filter('wpgmp_default_marker_icon', function($default_marker) {
    return 'http://yourwebsite.com/path-to-your-icon/custom_marker.svg';
});

Example 2

Using a marker icon from an external CDN to improve load times and reliability.

add_filter('wpgmp_default_marker_icon', function($default_marker) {
    return 'https://cdn.example.com/icons/cdn_marker.svg';
});

Example 3

Dynamically changing the marker icon based on a condition, such as the user’s role.

add_filter('wpgmp_default_marker_icon', function($default_marker) {
    if (current_user_can('administrator')) {
        return 'http://yourwebsite.com/icons/admin_marker.svg';
    }
    return $default_marker;
});

Tip: Always ensure that the URL you provide for the marker icon is accessible and properly formatted to avoid broken images on your maps. Consider using a child theme or a custom plugin for implementing this hook to prevent losing changes during updates.

The “wpgmp_marker_size” hook in WP Maps Pro allows developers to customize the marker sizes for different screens at runtime. This can be particularly useful for ensuring that markers are displayed appropriately on devices with varying screen resolutions, like mobile, desktop, and retina displays.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It provides the flexibility to adjust marker sizes by modifying the default sizes passed to the hook. This allows for improved display and usability of maps across different devices.

Example 1

This example demonstrates how to change the marker size for mobile screens to 30 pixels.

add_filter('wpgmp_marker_size', 'custom_mobile_marker_size');
function custom_mobile_marker_size($default_sizes) {
    $default_sizes['mobile'] = 30;
    return $default_sizes;
}

Example 2

In this scenario, the marker size for desktop screens is increased to 40 pixels, enhancing visibility on larger displays.

add_filter('wpgmp_marker_size', 'custom_desktop_marker_size');
function custom_desktop_marker_size($default_sizes) {
    $default_sizes['desktop'] = 40;
    return $default_sizes;
}

Example 3

This example focuses on optimizing marker size for retina displays, setting it to 70 pixels for sharper image quality.

add_filter('wpgmp_marker_size', 'custom_retina_marker_size');
function custom_retina_marker_size($default_sizes) {
    $default_sizes['retina'] = 70;
    return $default_sizes;
}

Tip: Always test your changes on multiple devices to ensure consistency and usability across different screen sizes. Proper validation and sanitization of any inputs or settings are crucial for maintaining security and performance.

This hook in the WP Maps Pro plugin allows developers to customize the size of the featured image that appears in the infowindow or listing when displaying a post as a location. It is triggered when rendering these images, and the default size is set to ‘medium’.

Usage

Developers can implement this hook in their theme’s functions.php file or in a custom plugin to adjust the featured image size according to their specific requirements. This can be useful for maintaining visual consistency or optimizing page load times by selecting appropriately sized images.

Example 1

This example demonstrates how to change the featured image size to ‘large’.

add_filter('wpgmp_featured_image_size', function($size, $post_id, $map) {
    return 'large';
}, 10, 3);

Example 2

In this case, the featured image size is set conditionally based on the post ID. If the post ID is 123, the size is set to ‘thumbnail’.

add_filter('wpgmp_featured_image_size', function($size, $post_id, $map) {
    if ($post_id == 123) {
        return 'thumbnail';
    }
    return $size;
}, 10, 3);

Example 3

Here, the hook changes the featured image size based on a specific map ID. If the map ID is 456, the size is set to ‘full’.

add_filter('wpgmp_featured_image_size', function($size, $post_id, $map) {
    if ($map->ID == 456) {
        return 'full';
    }
    return $size;
}, 10, 3);

Remember to test changes thoroughly in a staging environment before deploying them live to ensure compatibility and avoid any potential issues with image display.

The wpgmp_taxonomy_separator hook in WP Maps Pro allows developers to customize the separator used between multiple taxonomies when displayed on a map. By default, a comma is used as a separator, but this can be modified using this hook.

Usage

Developers can implement this hook within their theme’s functions.php file or through a custom plugin to change the default taxonomy separator. The hook provides flexibility to present taxonomy data in a format that best suits the application’s needs.

Example 1

Changing the taxonomy separator to a semicolon.

add_filter('wpgmp_taxonomy_separator', function($separator, $map) {
    return '; ';
}, 10, 2);

Example 2

Using a pipe character as a separator for a specific map ID.

add_filter('wpgmp_taxonomy_separator', function($separator, $map) {
    if ($map->ID == 123) {
        return ' | ';
    }
    return $separator;
}, 10, 2);

Example 3

Appending a custom text along with the comma separator.

add_filter('wpgmp_taxonomy_separator', function($separator, $map) {
    return ', and ';
}, 10, 2);

Tip: Always ensure the separator used is appropriate for your application’s context and doesn’t interfere with other text formats or functionality. Testing in a development environment before deploying changes to a live site is recommended.

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->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 = 'https://example.com/new-image.jpg';
    }
    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 = 'https://example.com/different-image.jpg';
    }
    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 = $custom_image_url;
    }
    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.

The wpgmp_marker_image_markup_post hook in WP Maps Pro allows developers to customize the HTML output of a marker image when the marker is associated with a post location. It provides flexibility to modify the marker image’s HTML markup dynamically.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. This hook is particularly useful when there is a need to alter the display attributes or add additional attributes to the marker image HTML based on specific criteria or conditions.

Example 1

In this example, we’ll add a custom CSS class to the marker image HTML for styling purposes.

add_filter( 'wpgmp_marker_image_markup_post', 'custom_marker_image_class', 10, 4 );

function custom_marker_image_class( $post_featured_image, $featured_image, $image_alt, $map_id ) {
    return '<img src="' . esc_url($post_featured_image) . '" alt="' . esc_attr($image_alt) . '" class="custom-marker-class">';
}

Example 2

This example demonstrates how to add a data attribute to the marker image HTML, which can be used for JavaScript interactivity.

add_filter( 'wpgmp_marker_image_markup_post', 'add_data_attribute_to_marker', 10, 4 );

function add_data_attribute_to_marker( $post_featured_image, $featured_image, $image_alt, $map_id ) {
    return '<img src="' . esc_url($post_featured_image) . '" alt="' . esc_attr($image_alt) . '" data-map-id="' . esc_attr($map_id) . '">';
}

Example 3

Here, we modify the HTML to include a tooltip displaying the post title when hovering over the marker image.

add_filter( 'wpgmp_marker_image_markup_post', 'marker_image_with_tooltip', 10, 4 );

function marker_image_with_tooltip( $post_featured_image, $featured_image, $image_alt, $map_id ) {
    $post_title = get_the_title($map_id);
    return '<img src="' . esc_url($post_featured_image) . '" alt="' . esc_attr($image_alt) . '" title="' . esc_attr($post_title) . '">';
}

Tip: Always ensure that data is properly sanitized and escaped when modifying HTML to prevent security vulnerabilities such as XSS (Cross-Site Scripting).

The wpgmp_show_place hook in WP Maps Pro allows developers to control the visibility of a specific location on a map. It is triggered when determining whether a location should be displayed or hidden, with a default value of true indicating the location will be shown.

Usage

Developers can implement this hook in their WordPress theme or plugin to conditionally show or hide a location on a map. By returning false, a location can be hidden based on custom logic, such as user roles or specific conditions.

Example 1

This example shows how to hide a location based on a specific user role.

add_filter('wpgmp_show_place', 'hide_location_for_non_admins', 10, 3);
function hide_location_for_non_admins($use_me, $place, $map) {
    if (!current_user_can('administrator')) {
        return false;
    }
    return $use_me;
}

Example 2

In this example, a location is hidden if it is marked as private in the custom field.

add_filter('wpgmp_show_place', 'hide_private_locations', 10, 3);
function hide_private_locations($use_me, $place, $map) {
    if (get_post_meta($place->ID, 'is_private', true) == 'yes') {
        return false;
    }
    return $use_me;
}

Example 3

This example demonstrates how to show a location only on specific maps.

add_filter('wpgmp_show_place', 'show_location_on_specific_map', 10, 3);
function show_location_on_specific_map($use_me, $place, $map) {
    $allowed_maps = array(1, 2, 3); // IDs of maps where the location should be visible
    if (!in_array($map->ID, $allowed_maps)) {
        return false;
    }
    return $use_me;
}

Always ensure to perform necessary checks and validations when modifying the visibility of locations using this hook, especially when dealing with sensitive or private data.

In WP Maps Pro, the wpgmp_marker_source hook allows developers to dynamically add or modify markers on maps. This hook is triggered when markers are being rendered, enabling custom marker data to be injected or existing data to be altered.

Usage

Developers can implement this hook within their theme’s functions.php file or within a custom plugin. The hook provides two parameters: $custom_markers and $map_id. By utilizing these parameters, developers can customize markers based on specific conditions or criteria relevant to each map instance.

Example 1

Adding a custom marker with additional information such as a fax number and email address.

add_filter('wpgmp_marker_source', 'add_custom_marker', 10, 2);
function add_custom_marker($custom_markers, $map_id) {
    if($map_id == 1) { // Check for a specific map ID
        $custom_markers[] = array(
            "category" => "Custom Category",
            "id" => "15987",
            "title" => "Custom Marker Title",
            "address" => "Custom Marker Address",
            "message" => "Info Window Custom Message",
            "latitude" => "30.210994",
            "longitude" => "74.94547450000005",
            "extra_fields" => array("fax" => "123456", "email" => "hello@flippercode.com"),
            "icon" => "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png"
        );
    }
    return $custom_markers;
}

Example 2

Modify existing markers to change their icon based on a condition.

add_filter('wpgmp_marker_source', 'modify_marker_icon', 10, 2);
function modify_marker_icon($custom_markers, $map_id) {
    foreach($custom_markers as &$marker) {
        if($marker['category'] == 'Special Category') {
            $marker['icon'] = 'https://example.com/new-icon.png';
        }
    }
    return $custom_markers;
}

Example 3

Remove markers from a specific category to filter the map display.

add_filter('wpgmp_marker_source', 'remove_specific_category_markers', 10, 2);
function remove_specific_category_markers($custom_markers, $map_id) {
    foreach($custom_markers as $key => $marker) {
        if($marker['category'] == 'Remove Category') {
            unset($custom_markers[$key]);
        }
    }
    return $custom_markers;
}

Tip: Always validate and sanitize any external data before using it within hooks to ensure security and prevent vulnerabilities such as XSS or SQL injection.

The wpgmp_markers hook in the WP Maps Pro plugin allows developers to customize the final list of markers assigned to a map. It is triggered when the map is being generated, providing an opportunity to modify the list of markers before they are rendered on the map.

Usage

Developers can implement this hook by adding a custom function to their theme’s functions.php file or a custom plugin. It is useful for altering marker data, such as filtering markers based on custom conditions or enhancing marker details dynamically.

Example 1

This example demonstrates how to filter markers based on a custom meta value.

add_filter('wpgmp_markers', 'filter_markers_by_meta', 10, 2);

function filter_markers_by_meta($filterd_places, $map_id) {
    $filtered = array();
    foreach ($filterd_places as $place) {
        if (get_post_meta($place->ID, 'custom_meta_key', true) == 'desired_value') {
            $filtered[] = $place;
        }
    }
    return $filtered;
}

Example 2

This example shows how to add additional information to each marker.

add_filter('wpgmp_markers', 'add_info_to_markers', 10, 2);

function add_info_to_markers($filterd_places, $map_id) {
    foreach ($filterd_places as &$place) {
        $place->extra_info = get_post_meta($place->ID, 'extra_info', true);
    }
    return $filterd_places;
}

Example 3

This example illustrates how to change marker icons based on a category.

add_filter('wpgmp_markers', 'change_marker_icons_by_category', 10, 2);

function change_marker_icons_by_category($filterd_places, $map_id) {
    foreach ($filterd_places as &$place) {
        $category = get_the_terms($place->ID, 'category');
        if (!empty($category)) {
            $place->icon = get_template_directory_uri() . '/images/icons/' . $category[0]->slug . '.png';
        }
    }
    return $filterd_places;
}

Always ensure that data used in hooks is validated and sanitized to maintain security and performance. Additionally, test changes in a staging environment before deploying to a live site.

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.