How to Insert Google Maps into WordPress

Right now, many people are using Google Maps to add more unique content to their visitors, such as showing their location of their business or event.

Today’s tutorial is how to insert Google Maps into WordPressPosts/Pages without a Plugin, we first need to write a Google Maps shortcodeand we can put our own maps easily into our WordPress posts.

The first time we write the code below in your theme functions.php and then we need to put the shortcode in our post/page with some parameters.

Code To Inserting Google Maps using shortcode

1
2
3
4
5
6
7
8
9
10
//Google Maps Shortcode
function do_googleMaps($atts$content = null) {
   extract(shortcode_atts(array(
      "width" => '640',
      "height" => '480',
      "src" => ''
   ), $atts));
   return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&amp;output=embed" ></iframe>';
}
add_shortcode("googlemap""do_googleMaps");

 

You can change the width and height to what ever you want. Just replace it in the code above.

Now it’s time to practice, to use this shortcode is easy, just write in your post/page

1
[googlemap width="200" height="200" src="[you_url]"]

You can Replace [you_url] with your Google Maps Link

There is also another method by using Inline Google Maps WordPress Plugin, if you need some tutorials about the Google Maps Plugin you can try using this tutorial, thanks go to DigWP for sharing his tricks.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>