Post Pic

WordPress shortcode to easily integrate a Google Map on your blog

Google Maps are very useful to show locations on your blog, but they can be a bit tricky to integrate, especially for client or non tech-savvy users. Here is a shortcode that will make Google Maps integration super easy.

To create the shortcode, paste the code below into your functions.php file:

function rockable_googlemap($atts, $content = null) {
   extract(shortcode_atts(array(
               "width" => '940',
               "height" => '300',
               "src" => ''
   ), $atts));
 
return '<div>
         <iframe src="'.$src.'&output=embed" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="'.$width.'" height="'.$height.'"></iframe>
        </div>
       ';
}
 
add_shortcode("googlemap", "rockable_googlemap");

Once you saved your function.php file, you can start integrating Google Maps into your posts and pages. To do so, get the url of the map you'd like to display, and use the shortcode as shown below:

[googlemap src="google_map_url"]

or with custom width and height parameters:

[googlemap width="600" height="250" src="google_map_url"]

Thanks to Rockable Themes for the tip!

2 Responses

Jan 29 2013 19:37

Is it possible to add custom text to the marker pin through this shortcode?

Apr 22 2013 15:59

Adding custom text to marker pin is only possible if you have generated google maps api.
This is the same shortcode google would give you.
Only here is that its been made with an array,which you can make widget for example so users can fill this in themselves.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox