shortcode Archives - WP Maps Pro

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

Hook Category: shortcode

This hook allows developers to customize the functionality of rendering shortcodes within the infowindow message in the WP Maps Pro plugin. It is triggered during the rendering process of these shortcodes, providing an opportunity to modify or extend the behavior.

Usage

Developers can implement this hook in their themes or plugins to alter how shortcodes are rendered in the infowindow message. This can be done by adding a filter to modify the boolean data based on the map instance provided. It is especially useful for adding custom logic or conditions when rendering shortcodes.

Example 1

Enable shortcode rendering only for a specific map ID.

add_filter('wpgmp_render_shortcode', 'custom_render_shortcode_logic', 10, 2);
function custom_render_shortcode_logic($render, $map) {
    if ($map->id == 5) { // Check for map ID 5
        return true; // Enable shortcode rendering
    }
    return $render; // Default behavior for other maps
}

Example 2

Disable shortcode rendering based on a specific condition, such as checking user roles.

add_filter('wpgmp_render_shortcode', 'disable_shortcode_for_non_admins', 10, 2);
function disable_shortcode_for_non_admins($render, $map) {
    if (!current_user_can('administrator')) {
        return false; // Disable shortcode rendering for non-admin users
    }
    return $render;
}

Example 3

Modify the infowindow message content based on a custom field value.

add_filter('wpgmp_render_shortcode', 'custom_infowindow_content_logic', 10, 2);
function custom_infowindow_content_logic($render, $map) {
    if (get_post_meta($map->post_id, 'custom_field_key', true) == 'special_value') {
        return true; // Render shortcodes if custom field matches
    }
    return $render;
}

Tip: Always ensure that any conditions or modifications performed within the hook are secure and do not expose vulnerabilities to your WordPress site. Validate and sanitize any user input or data used in your hook implementations.

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.

This hook in the WP Maps Pro plugin allows developers to customize functionality at runtime, specifically for rendering a shortcode if it exists in the listing below the map. It is triggered when the plugin attempts to render a listing that might include shortcodes.

Usage

Developers can implement this hook to modify the rendering process of listings in WP Maps Pro. It is particularly useful when you want to enable or disable the rendering of specific shortcodes based on certain conditions. The hook provides a boolean value that can be altered before the shortcode is rendered.

Example 1

Enable shortcode rendering only for specific map IDs.

add_filter('wpgmp_listing_render_shortcode', function($render_shortcode, $map) {
    $allowed_map_ids = array(1, 2, 3); // IDs of maps that allow shortcode rendering
    if (in_array($map->id, $allowed_map_ids)) {
        return true;
    }
    return false;
}, 10, 2);

Example 2

Disable shortcode rendering during certain hours of the day to manage server load.

add_filter('wpgmp_listing_render_shortcode', function($render_shortcode, $map) {
    $current_hour = date('G');
    if ($current_hour >= 9 && $current_hour <= 17) { // Disable between 9 AM and 5 PM
        return false;
    }
    return true;
}, 10, 2);

Example 3

Conditionally render shortcodes based on user role. Only admins can render shortcodes.

add_filter('wpgmp_listing_render_shortcode', function($render_shortcode, $map) {
    if (current_user_can('administrator')) {
        return true;
    }
    return false;
}, 10, 2);

Tip: Always ensure that your conditions in the hook are well-tested to avoid unexpected behavior, especially when dealing with user roles and server load.

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.