wpgmp_listing_render_shortcode - WP Maps Pro

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

wpgmp_listing_render_shortcode

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.