The [leaflet-marker] shortcode we saw in the previous post is the starting point, but Leaflet Map offers quite a few more options to customize the markers on your map: changing the icon, adding tooltips, controlling how the popup behaves, or using markers with Font Awesome icons thanks to the companion plugin Extensions for Leaflet Map.
Here we’ll go over what you can do with markers in Leaflet Map, with examples so you can clearly understand how to work with them on your maps. We’ll leave the more advanced features for a future post: clustering, marker lists, automatic overview maps and more.
If you don’t have Leaflet Map installed, start here: How to install and set up Leaflet Map from scratch.
The native marker
As we saw in the previous post, adding a basic marker to a base map made with Leaflet Map is very easy. Basically, after the base map shortcode [leaflet-map] we add the marker shortcode with the coordinates and, if we want, we can include text for the marker’s popup:
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-marker lat=37.1760 lng=-3.5880]Alhambra[/leaflet-marker]This places a standard blue pin on the map with a popup that shows the text “Alhambra” when clicked. From here, let’s see how to improve it.

Tooltip with title
The title parameter shows a text label when you hover over the marker, without needing to click:
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Alhambra"]Monumento más visitado de España[/leaflet-marker]
💡
titleis an important parameter beyond the tooltip: you’ll need it if you later use[listmarker]or[targetmarker]from the Extensions for Leaflet Map plugin. If you don’t include thetitle, those modules won’t be able to identify the marker.
Popup open by default with visible
If you want a marker’s popup to appear open as soon as the map loads, without the user having to click, you’ll need to use the visible parameter:
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-marker lat=37.1760 lng=-3.5880 visible=1]Alhambra[/leaflet-marker]
This is very useful on detail pages about a specific place, where there may be other markers but that particular marker is the star of the map.
Draggable marker with draggable
Now imagine we want to be able to drag the marker around the map ourselves and move it somewhere else. For that, we’ll use the draggable parameter:
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-marker lat=37.1760 lng=-3.5880 draggable=1]Arrastra este marcador[/leaflet-marker]
To be honest, it’s rarely used on production maps, but it could be useful if you’re building interactive tools or want to demonstrate coordinates in a tutorial.
HTML in the popup
So far we’ve been adding plain text to the markers’ content, but you may be interested to know that it accepts basic HTML:
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-marker lat=37.1760 lng=-3.5880]
<b>Alhambra</b><br>
Siglo XIII · <a href="https://www.alhambra-patronato.es" target="_blank">Web oficial</a>
[/leaflet-marker]Custom icon with your own image
Leaflet Map’s standard blue pin is fine, but we should be able to use other options, and one of them is replacing it with any image. The parameter for this is iconUrl:
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-marker lat=37.1760 lng=-3.5880 iconUrl="https://tudominio.com/wp-content/uploads/icono-monumento.png" iconSize="32,32" iconAnchor="16,32" popupAnchor="0,-32"]Alhambra[/leaflet-marker]
It’s important to clarify the size and position parameters here, so we understand how to position the image correctly and make it behave properly without doing strange things:
iconSize: the size of the icon in pixels, in"width,height"format. For example"32,32"for a 32px square icon.iconAnchor: the point of the icon that is anchored to the geographic coordinate, in"x,y"format. For a 32×32 icon with the tip at the bottom, the correct value is"16,32": horizontal center, bottom edge.popupAnchor: the position of the popup relative to the icon, in"x,y"format. With"0,-32"the popup appears above the icon and won’t overlap the marker.tooltipAnchor: the same aspopupAnchorbut for the tooltip.
💡 The
iconAnchorvalue is the most confusing one. Think of it this way: it’s the pixel of the image that will line up exactly with the point on the map. If your icon is a pushpin with the tip at the bottom, that pixel is the horizontal center of the image’s bottom row.
Adding a shadow to the marker
We can add a shadow to the marker. To do this we need an image of the shadow, since it isn’t an effect as such, and we’ll have to use a small workaround to create that sense of depth. In the following example, look at the shadowURL parameter, which defines the shadow image, shadowSize, which sets its size, and shadowAnchor, which sets the shadow’s anchor point, separate from that of the image itself:
[leaflet-marker lat=37.1760 lng=-3.5880 iconUrl="https://tudominio.com/icono.png" iconSize="32,32" iconAnchor="16,32" shadowUrl="https://tudominio.com/sombra.png" shadowSize="40,20" shadowAnchor="12,20"]Alhambra[/leaflet-marker]

Several markers with different icons
It’s very common to have different types of markers on the same map. With custom icons you can tell them apart visually:
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-marker lat=37.1760 lng=-3.5880 iconUrl="https://tudominio.com/icono-monumento.png" iconSize="32,32" iconAnchor="16,32"]<b>Alhambra</b><br>Monumento[/leaflet-marker]
[leaflet-marker lat=37.1767 lng=-3.5994 iconUrl="https://tudominio.com/icono-iglesia.png" iconSize="32,32" iconAnchor="16,32"]<b>Catedral de Granada</b><br>Iglesia[/leaflet-marker]
[leaflet-marker lat=37.1771 lng=-3.5902 iconUrl="https://tudominio.com/icono-museo.png" iconSize="32,32" iconAnchor="16,32"]<b>Museo de la Alhambra</b><br>Museo[/leaflet-marker]
⚠️ This approach works well with a few markers. But if you have lots of points in different categories, the
[geojsonmarker]module from Extensions for Leaflet Map is much more efficient. We’ll look at that in the next post.
Markers with Font Awesome icons
If the previous option falls short for you, the Extensions for Leaflet Map plugin lets us liven up our markers a bit, since it lets us tell them apart more easily by adding Font Awesome icons. This gives us markers with vector icons without having to prepare PNG images.
Extensions for Leaflet Map includes the [leaflet-extramarker] shortcode, based on the Leaflet.ExtraMarkers library.
The first thing you need to do is install Extensions for Leaflet Map:
- Go to Plugins > Add New.
- Search for Extensions for Leaflet Map.
- Install and activate it.
Let’s look at a basic example where we create a red marker (markerColor="red") and, instead of the usual marker shape, give it a circular one (shape="circle"). We also add an icon with a museum symbol (icon="fa-landmark"). Note that you also need to add prefix="fa".
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-extramarker lat=37.1760 lng=-3.5880 markerColor="red" shape="circle" icon="fa-landmark" prefix="fa" title="Alhambra"]Alhambra[/leaflet-extramarker]
This way we can add several markers that differ in both color and icon:
[leaflet-map zoom=13 lat=37.18 lng=-3.60]
[leaflet-extramarker lat=37.1760 lng=-3.5880 markerColor="red" shape="circle" icon="fa-landmark" prefix="fa" title="Alhambra"]<b>Alhambra</b><br>Monumento[/leaflet-extramarker]
[leaflet-extramarker lat=37.1767 lng=-3.5994 markerColor="blue" shape="square" icon="fa-church" prefix="fa" title="Catedral de Granada"]<b>Catedral de Granada</b><br>Iglesia[/leaflet-extramarker]
[leaflet-extramarker lat=37.1771 lng=-3.5902 markerColor="green" shape="circle" icon="fa-building-columns" prefix="fa" title="Museo de la Alhambra"]<b>Museo de la Alhambra</b><br>Museo[/leaflet-extramarker]
[leaflet-extramarker lat=37.1804 lng=-3.5862 markerColor="orange" shape="star" icon="fa-tree" prefix="fa" title="Jardines del Generalife"]<b>Jardines del Generalife</b><br>Jardín[/leaflet-extramarker]
Several colors are available for markerColor: red, blue, green, orange, purple, darkred, darkblue, darkgreen, cadetblue, white, black, gray
As for the shapes available for shape, we have: circle, square, star, penta
⚠️ If the
titlehas more than one word, always put it in quotes:title="Jardines del Generalife". Without quotes, the shortcode only processes the first word and the rest disappears.
When to use each type of marker
It’s worth knowing when to use each marker so you don’t waste resources or use a sledgehammer to crack a nut. So:
For simple maps with few points where appearance isn’t a priority and you don’t need extra dependencies, use the native [leaflet-marker] marker with the standard pin.
When you have your own icons designed specifically for your project and want full control over the image, I recommend the native [leaflet-marker] marker with iconUrl.
When you need to tell types of places apart visually with colors and shapes, without preparing images, use [leaflet-extramarker]. It requires the additional Extensions for Leaflet Map plugin.
In an upcoming post we’ll look at the advanced features of Extensions for Leaflet Map: clustering for maps with many markers, marker lists, markers from GeoJSON files and automatic overview maps built from your WordPress content.

Leave a Reply