wpsl_map_shortcode_defaults

  1. Description
  2. Parameters
  3. Usage
  4. Changelog
  5. Source File
  6. Related

Description

This filter changes the default attributes of the [wpsl_map] shortcode. The defaults apply to every [wpsl_map] on the site.

Most defaults come from the Map settings on Store Locator > Settings > Map. Change the setting there if you want the same result on the [wpsl] map. Use this filter if you only want to change the [wpsl_map] maps.

You can also set the attributes on a single shortcode, for example [wpsl_map id="123" height="400"]. Attributes on the shortcode override the defaults from this filter.

Parameters

$shortcode_defaults - (array) The default shortcode attributes.

KeyDefaultDescription
id''One or more store IDs, separated by commas. On a store page the current store is used when it's empty.
category''One or more category slugs, separated by commas. Shows the published stores in these categories.
city, state, country''Shows the published stores whose City, State or Country field exactly matches the value. If you set more than one, a store must match all of them.
width''The width in pixels, as a number. Empty uses the full width.
height350The height in pixels, as a number.
zoomThe "Initial zoom level" setting.A number from 1 to 21. Other values fall back to the setting.
map_typeThe "Map type" setting.roadmap, satellite, hybrid or terrain. Google Maps only.
map_type_controlThe "Show the map type control?" setting.Show the map type control. Google Maps only.
map_style''A map style for this map. The values depend on the map provider, see below.
map_id''A Google Map ID for this map. Google Maps only.
street_viewThe "Show the street view controls?" setting.Show the Street View control. Google Maps only.
scrollwheelThe "Enable scroll wheel zooming?" setting.Zoom the map with the scroll wheel.
control_positionThe "Zoom control position" setting.left or right.
marker_clusters''Set to 1 to turn on marker clustering for this map. Empty or 0 uses the "Enable marker clusters?" setting, so it can't turn clustering off. marker_cluster works too.
shapes1Set to 0 to hide the map shapes on this map.
store_marker''The marker for the stores on this map. Use a marker name like red or dark-green, or a Marker Studio marker. Unknown names use blue. Empty uses the marker settings.
active_marker''The marker for the selected store. Unknown names use dark-blue. Empty uses the marker settings.

For the on / off keys, 1 or true means on, and 0 or false means off.

Which stores are shown

The shortcode uses the first of these that is set:

  1. category
  2. city, state or country
  3. id

So when category is set, id is ignored. Outside a store page you need at least one of them, otherwise the map isn't shown. Only stores with coordinates appear on the map.

Map provider notes

map_type, map_type_control, street_view and map_id only work with Google Maps. The other map providers ignore them.

The values for map_style depend on the map provider. custom uses the custom style URL from Store Locator > Appearance > Map Style. An unknown value is ignored, and the map then uses the style from that page.

Map providermap_style values
Google Mapsdefault, to turn off the JSON style for this map. In 3.0.3 this has no effect yet.
Mapboxstreets, outdoors, light, dark, satellite, satellite-streets, navigation-day, navigation-night, standard, standard-satellite and custom
OpenStreetMapdefault for the standard OpenStreetMap tiles, the OpenFreeMap styles liberty, bright, positron, dark and fiord, and custom
Stadia MapsThe OpenStreetMap values, plus alidade_bright, alidade_smooth, alidade_smooth_dark, osm_bright, outdoors, stamen_terrain, stamen_toner, stamen_toner_lite, stamen_toner_dark and stamen_toner_blacklite

With OpenStreetMap you can also use the Stadia Maps styles when a valid Stadia Maps API key is saved. With OpenStreetMap and Stadia Maps you can use the Mapbox styles, except standard and standard-satellite, when a valid Mapbox API key is saved.

Usage

This example makes every [wpsl_map] 500 pixels high, and turns off scroll wheel zooming on these maps. A height or scrollwheel attribute on a shortcode still overrides them.

add_filter( 'wpsl_map_shortcode_defaults', 'custom_map_shortcode_defaults' );
function custom_map_shortcode_defaults( $shortcode_defaults ) {
// Make every [wpsl_map] 500px high, unless the shortcode sets its own height.
$shortcode_defaults['height'] = 500;
// Turn off scroll wheel zooming on these maps. The [wpsl] map keeps the setting from the Map tab.
$shortcode_defaults['scrollwheel'] = 0;
return $shortcode_defaults;
}

With Google Maps, a map without scroll wheel zooming usually switches to cooperative gestures, so visitors zoom with Ctrl + scroll. See wpsl_gesture_handling.

Changelog

VersionDescription
3.0Moved to includes/frontend/shortcodes/class-shortcodes.php. Added the map_id, marker_clusters (or marker_cluster), shapes, store_marker, active_marker, city, state and country keys. map_style accepts style names for Mapbox, OpenStreetMap and Stadia Maps. Outside a store page, city, state or country can be used instead of id or category.
2.1.0Added the category key.
2.0.3Removed the pan_controls and control_style keys.
2.0Introduced.

Source File

This filter is located in /includes/frontend/shortcodes/class-shortcodes.php.

Placement

The code needs to be placed in the functions.php file inside your active theme folder.