WordPress shortcode to easily integrate a Google Map on your blog

January 28, 2013 at 5:13 pm

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!

Tags: