X

Google maps shortcode

Adding the first block of code to your functions.php will allow you to use shortcode to add google maps to your wordpress blog.


function fn_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.'"></iframe>';
}
add_shortcode("googlemap", "fn_googleMaps");
[googlemap width="200" height="200" src="[url]"]

Comments  Leave a Reply

  1. Hi, nice idea, but for me the map doesn’t show up either, only a blank field. Any suggestions what went wrong???

  2. Hi Cliff a few things including if changes are made to the embed code in the embed code you can just update the snippet rather then update each post. You may want to have multiple sizes for each post or you may in the future change the design of your site and need each map a specific size that you could ignore the size att and force a default one.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!