Craig Simpson

Web developer from Moray, Scotland

How to filter the FacetWP Google Maps options

23rd March 2017

No Comments

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.

1add_filter( 'facetwp_map_init_args', 'prefix_prevent_scroll_zoom_on_facet_map' );
2/**
3 * Filter the Google Map options to prevent scrollwheel zoom.
4 * @link https://craigsimpson.scot/code/filter-facetwp-google-map-options
5 *
6 * @param array $args Array of init settings for Google map.
7 *
8 * @return array $args Modified array.
9 */
10function prefix_prevent_scroll_zoom_on_facet_map( $args ) {
11 $args['init']['scrollwheel'] = false;
12 return $args;
13}

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

Leave a Reply

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