How to filter the FacetWP Google Maps options

This morning I was helping to work out some issues with a site using FacetWP and came across a useful filter contained within the Facet WP Google Maps addon.

Documentation for the Google Maps addon is a little sparse at the moment, so I thought it would be helpful to highlight the facetwp_map_init_args filter, which allows you to update the default Google Map options.

In this case we wanted to disable the scrollwheel zoom, so added the following code to functions.php.

<?php
add_filter( 'facetwp_map_init_args', 'prefix_prevent_scroll_zoom_on_facet_map' );
/**
* Filter the Google Map options to prevent scrollwheel zoom.
* @link https://craigsimpson.scot/filter-facetwp-google-map-options
*
* @param array $args Array of init settings for Google map.
*
* @return array $args Modified array.
*/
function prefix_prevent_scroll_zoom_on_facet_map( $args ) {
$args['scrollwheel'] = false;
return $args;
}
view raw functions.php hosted with ❤ by GitHub

Other Google Maps options can be set using the filter, such as preventing the map being draggable or removing the default map controls.

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *