How to install and set up Leaflet Map in WordPress from scratch

Want to put a map on your WordPress site without relying on Google Maps, without paying for an API and without touching a single line of code? That’s exactly what we’ll cover in this tutorial. We’ll install the Leaflet Map plugin, create a map from scratch, add markers with popups and publish the map on…

destacada como instalar leaflet map

Want to put a map on your WordPress site without relying on Google Maps, without paying for an API and without touching a single line of code? That’s exactly what we’ll cover in this tutorial.

We’ll install the Leaflet Map plugin, create a map from scratch, add markers with popups and publish the map on a WordPress page.

For the demo we’ll use WordPress Playground, an official tool that gives you a working WordPress site in your browser without installing anything at all. If you already have your own WordPress site, the steps are exactly the same.

To create a new WordPress site with Playground, just go to playground.wordpress.net.

At the end of the post you’ll find a video (in Spanish) with the full explanation.

What Leaflet Map is

I don’t think I need to explain it. In short, Leaflet Map is a free WordPress plugin that uses the Leaflet.js library, which is open source and one of the most widely used in the world for interactive web maps.

Unlike Google Maps:

  • You don’t need a Google account.
  • You don’t need a credit card.
  • There’s no visit limit that generates costs.

It has been in the WordPress directory for more than ten years, has over 30,000 active installations and a very high rating. It’s a mature, stable and well-maintained plugin.

If you want to know more about what Leaflet.js is and why it’s the best option for maps in WordPress, here’s the full post where I explain what Leaflet Map is. And in this other one I explain what Leaflet is.

Installing the Leaflet Map plugin

Installation is the same as for any free plugin from WordPress.org:

  1. Go to Plugins > Add New.
  2. In the search box type: Leaflet Map.
  3. Click Install Now.
  4. Once installed, click Activate.

Configuring the default settings (Settings)

The first step is to go to Leaflet Map > Settings. This is where you define the options that will apply by default to every map you create.

There are lots of options, but to get started you only need to change two:

Default center coordinates

The Default Latitude and Default Longitude fields define the center of the map when it loads. You can enter the coordinates of your city or of the geographic area you’re interested in.

For example, to center the map on Granada:

  • Latitude: 37.18
  • Longitude: -3.60

💡 To get the coordinates of any point, open Google Maps, right-click on the place and copy the coordinates shown as the first item in the context menu.

Map height

By default the maps come out quite flat. Change the height field to 500px so they look good on most pages.

Once you’ve changed these values, click Save Changes.

Using the Shortcode Helper to prepare the map

Go to Leaflet Map > Shortcode Helper. This section is very useful because it lets you:

  • See a map in real time while you adjust the parameters.
  • Generate the correct shortcode without typing it by hand.
  • Copy the shortcode, ready to paste into any page or post.

When you move the map, the center coordinates change. When you change the zoom, the zoom number updates. When you move the marker, its coordinates change. All in real time.

How shortcode stacking works

Leaflet Map works by stacking shortcodes: the base map is defined with one shortcode, and the elements you add (markers, layers, etc.) are inserted with additional shortcodes below the first one.

Basic example for a map with one marker:

[leaflet-map zoom=12 lat=37.18 lng=-3.60]

[leaflet-marker lat=37.1760 lng=-3.5880]

Adding the map to a page

  1. Copy the map shortcode shown in the Shortcode Helper.
  2. Go to Pages > Add New.
  3. In the block editor (Gutenberg), click + to add a block and search for the Shortcode block.
  4. Paste the map shortcode into the block.
  5. Click Preview to see the result.

⚠️ If you use the classic editor instead of Gutenberg, paste the shortcode directly into the text area of the post or page. It works the same way.

Adding markers with popups

A marker points to a specific spot on the map. It can have a popup with text that opens when clicked.

How to generate a marker shortcode

  1. In the Shortcode Helper, move the marker to the exact point you want to show.
  2. Copy the marker shortcode shown in the panel.
  3. On your page, paste it below the map shortcode.

To add text to the popup, edit the shortcode like this:

[leaflet-marker lat=37.1760 lng=-3.5880]Alhambra[/leaflet-marker]

The text between the opening and closing tags is the popup content. The plugin accepts basic HTML, so you can use bold, line breaks and so on:

[leaflet-marker lat=37.1760 lng=-3.5880]<b>Alhambra</b><br>Spain's most visited monument[/leaflet-marker]

Adding more markers

To add a second marker (or as many as you need), just repeat the process and add another shortcode below:

[leaflet-map zoom=13 lat=37.18 lng=-3.60]

[leaflet-marker lat=37.1760 lng=-3.5880]<b>Alhambra</b>[/leaflet-marker]

[leaflet-marker lat=37.1767 lng=-3.5994]<b>Granada Cathedral</b>[/leaflet-marker]

You can add as many markers as you need. The Shortcode Helper makes it easy: move the marker to the point you want, copy the shortcode and paste it into your page.

Customizing the map: basic options

Leaflet Map lets you customize how the map behaves through shortcode parameters and options in Settings. The most useful ones to start with:

Adding or removing the zoom control

By default the map doesn’t show the +/– zoom buttons. To add them:

[leaflet-map zoom=12 lat=37.18 lng=-3.60 zoomcontrol=1]

Scroll wheel

The scroll wheel option lets you zoom with the mouse wheel. It’s convenient for the user, but it can be very annoying on long pages: the visitor is scrolling and suddenly the map starts zooming.

My recommendation is not to enable it, unless the map takes up the whole screen or is the main element on the page.

💡 In Settings you can change these options so they apply to all maps by default, without having to add them to each map’s shortcode.

Conclusion and next steps

In this tutorial we’ve seen how to:

  • Install the Leaflet Map plugin from the WordPress directory.
  • Configure the default options (center coordinates, map height).
  • Use the Shortcode Helper to prepare the map and copy the shortcode.
  • Add the map to a WordPress page with the Shortcode block.
  • Create markers with popups, including basic HTML.
  • Add several markers to the same map.
  • Control basic options such as zoom and the scroll wheel.

All without touching a single line of code.

But, as you know, Leaflet Map has many more possibilities. So I encourage you to explore the Shortcode Helper and start trying them out. I’ll be writing more about this plugin, which I like so much.

Jesús Yesares-García Avatar

Leave a Reply

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