- Choose a Marker on the Store Edit Screen
- Create Your Own Marker
- Use a Marker URL from a Custom Field
Choose a Marker on the Store Edit Screen
When you edit a store, the Marker box is shown next to the store details. It has two dropdowns:
- Normal: the marker shown on the map.
- Active: the marker shown when the location is selected on the map.
The Default option shows the marker that’s used when you don’t pick one: the marker of the store’s category, or otherwise the marker from the settings page. A marker you pick here takes priority over both, and it’s used in the store locator and on the store pages.
Below the dropdowns, Design a Marker and Use Your Own Image take you to the Marker Studio.
Create Your Own Marker
- Go to Store Locator > Marker Studio.
- Design your marker: pick a shape and colors, and add an icon, up to two characters of text, or your logo. To use your own image instead, go to My Image and upload it.
- Click Save Marker to add it to the Library.
- Edit a store, and select the new marker in the Marker box.
The marker is now used in the store locator and on the store pages. No code is needed for this. Your saved markers also show up in the marker dropdowns on the category screen and the settings page.
Use Size in the Marker Studio to set how big the marker is shown on the map.
Use a Marker URL from a Custom Field
If you pick your markers in the Marker box, you don’t need any of the code below. It’s only needed when the marker URLs come from somewhere else, for example an import. In that case you can store them in a custom field and use them with code. A marker URL from a custom field takes priority over the marker you pick in the Marker box.
First create the field. The easiest way is under Store Locator > Settings > Fields Manager: add a field with the Label “Marker URL” and the Type “Url”, and change the Name to alternate_marker_url. The code below uses that name to find the value, so it has to match exactly.
You can also create the field with the wpsl_meta_box_fields filter. This adds the same field to the bottom of the “Additional Information” tab, and the plugin’s own fields on that tab stay in place.
| add_filter( 'wpsl_meta_box_fields', 'custom_meta_box_marker_url' ); | |
| function custom_meta_box_marker_url( $meta_fields ) { | |
| // Add the field to the bottom of the "Additional Information" tab. | |
| $tab = esc_html__( 'Additional Information', 'wp-store-locator' ); | |
| $meta_fields[ $tab ]['alternate_marker_url'] = [ | |
| 'label' => esc_html__( 'Marker URL', 'your-textdomain' ), | |
| 'type' => 'url', | |
| ]; | |
| return $meta_fields; | |
| } |
Use the Marker in the Store Locator
The wpsl_store_meta filter passes the URL to the map under the alternateMarkerUrl key, which the map uses instead of the default marker. It also uses the same URL for locationMarkerUrlActive, so the marker doesn’t change back to the default active marker when a location is selected. You need this code for a field created in the Fields Manager as well.
| add_filter( 'wpsl_store_meta', 'custom_store_meta_marker_url', 10, 2 ); | |
| function custom_store_meta_marker_url( $store_meta, $store_id ) { | |
| $marker_url = esc_url_raw( get_post_meta( $store_id, 'wpsl_alternate_marker_url', true ) ); | |
| // Use the same marker for the normal and the active ( selected ) state. | |
| if ( $marker_url ) { | |
| $store_meta['alternateMarkerUrl'] = $marker_url; | |
| $store_meta['locationMarkerUrlActive'] = $marker_url; | |
| } | |
| return $store_meta; | |
| } |
Use the Marker on the Store Pages
The marker on the store pages and on [wpsl_map] maps uses different data, so it needs the wpsl_cpt_info_window_meta_fields filter as well:
| add_filter( 'wpsl_cpt_info_window_meta_fields', 'custom_cpt_info_window_marker_url', 10, 2 ); | |
| function custom_cpt_info_window_marker_url( $store_meta, $store_id ) { | |
| $marker_url = esc_url_raw( get_post_meta( $store_id, 'wpsl_alternate_marker_url', true ) ); | |
| // Use the same marker for the normal and the active ( selected ) state. | |
| if ( $marker_url ) { | |
| $store_meta['alternateMarkerUrl'] = $marker_url; | |
| $store_meta['locationMarkerUrlActive'] = $marker_url; | |
| } | |
| return $store_meta; | |
| } |
Markers from a URL are shown at 24 x 35 pixels, the same as the bundled markers. Those are 48 x 70 pixel images, so they stay sharp on high-resolution screens, and that’s also the best size for your own marker images. To show markers at a different size, use the wpsl_marker_props filter.