How to Insert Google Map Into WordPress Site

Are you looking for a way to put a map of your country or city on your website? You can use a service like Google Maps and Waze to do that. But there’s another option that you should look into. It’s called “Insert Map” within WordPress. In this blog post, we’ll show you how to do that. So let’s get started.

Get The HTML Code

The first step is to get the HTML code of the map you want to insert. For this tutorial, we’ll be using the Google Maps JavaScript API to get the HTML code of the London underground. To get the code, click on this link and you’ll be taken to a JavaScript console. Copy and paste the following code into the console:

  • var map (DOMElement) (HTMLDocument)
  • href (string) (attribute) (HTMLDocument)
  • title (string)
  • width (number)
  • height (number)
  • zoom (number)
  • scale (number)

You’ll notice that this code fetches the HTML code of the first webpage that matches the given search criteria. In this case, we’re searching for an underground map for London. So we get the HTML code for the Google Maps website for London. Don’t worry. This code is totally free!

Depending on how much content you have on your website, this step alone could take a while. So be patient.

Wrap The HTML Code In A PHP Function

After you have the HTML code for the map you want to use, you should wrap it in a PHP function. This will help you reuse the code on several of your pages. To do this, click on the PHP button within the JavaScript console to open up the PHP editor. Then type the following code:

  • add_action (string) (array) (integer)
  • description (string)
  • function (string) (array) (string)
  • handler (DOMElement)
  • name (string)
  • parent (DOMElement)
  • role (string)

This code adds an “add_action” function, which will be called whenever someone visits a page with the given search criteria. Inside the function, you’ll find an array with all the HTML code for the map you want to use. In this case, we have a handler named “map”, which means that this is the JavaScript function that will be called whenever someone visits a page with the “add_map” class.

A parent element is used to signify where this code will be inserted. In this case, we’re using a div element with the class “add_map”. This class will be applied to all the pages that you want this content to appear on. The role attribute is used to specify the HTML code’s role. In this case, it’s just a text node with the word “map”. So if you want to put a map on your blog about California, you could use the following code:

  • add_action (string) (array) (integer)
  • description (string)
  • function (string) (array) (string)
  • handler (DOMElement)
  • name (string)
  • parent (DOMElement)
  • role (string)

The only difference between this code and the previous code is the class “add_map”. This class will be added to the div element whenever someone visits a page with the add_map class. So in this case, whenever someone visits a page with the “California” topic, the div will have the class “add_map” applied to it. You can use this class to style your map content easily.

This is just one example of how you could use the “add_action” function. You can think of the roles array as a property bag for the “add_action” function. So if you wanted to make another change inside this function, you could replace the contents of the roles array with something new.

Call The Function On An OnClick Event

When someone clicks on a map listing within Google Maps, a call is made to the JavaScript function that was specified earlier. This is what we want to happen when someone clicks on a listing of our underground railway map in Google Maps. We want to call the function so that the above code is applied and the corresponding HTML is displayed on our website. To do that, click on the map listing and add the following code to the top of the page:

  • onclick (string) (DOMElement)
  • map (string)

Then add this code at the end of the function:

  • return (string)

This code tells the browser that whenever someone clicks on a given element, the function should be called and its output should be used. In this case, we’re returning the HTML code for the map. When someone clicks on the map, they’ll see the London Underground map.

Paste The HTML Code Into Your WordPress Content

With all that code out of the way, it’s time to paste it into your WordPress content. To do that, follow these steps:

  1. Click on the Add New button to open up the WordPress dashboard.
  2. Click on the Text tab in the upper left-hand corner.
  3. Click on the button next to the page title
  4. Click on the button next to the text area
  5. Paste the HTML code you got from Google Maps (or Waze) into the text area
  6. Click on the Publish button to save the content.

That’s it! Now whenever someone visits a page with the add_map class, they’ll see the London Underground map. Of course you can style it any way you want using CSS.

You can find the source code for this tutorial on this GitHub page. And if you want to learn more about inserting maps into WordPress sites, check out the WordPress documentation on adding Google Maps.

To be able to use the Google Maps JavaScript API, you’ll need to have a Google account. If you don’t have one yet, you can sign up for one here. Once you have a Google account, you can log in to your Google Dashboard and visit the API’s “My Maps” page. Click on the Create button and you’ll see a map of your currently available accounts. You can click on “London Underground” within the API to see all the maps you can make for the city. You can also find a map of London here. Just don’t use the GIF map type, as that’s not supported by the API.