Google Maps Shortcode for WordPress

/Google Maps Shortcode for WordPress

Note: This method no longer works as intended due to changes in WordPress and Google maps. However, if you paste the iframe information from the Google maps page, WordPress automatically converts the frame to its own shortcode for you. At least, it’s supposed to work that way.

Adding Google maps to your WordPress installation isn’t actually difficult at all. Simply add this to your functions.php file and call using the resulting

[ googlemap ] shortcode.

//Google Maps Shortcode
function fn_googleMaps($atts, $content = null) {
"width" => '640',
"height" => '480',
"src" => ''
), $atts));
return '';
add_shortcode("googlemap", "fn_googleMaps");

And then inside the post itself:

[googlemap width="200" height="200" src="[url]"]


View Larger Map

2018-02-02T03:09:38+00:00March 21st, 2011|WordPress Snippets|6 Comments

About the Author:

Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.


  1. Tyler June 11, 2011 at 4:20 pm - Reply

    At least, it’s supposed to work that way.

    That support article seems to refer to blogs, rather than independent WordPress installations, just for the record.

    • SuperWaz June 11, 2011 at 6:02 pm - Reply

      It is indeed a reference, you’re correct. The same information did once apply to both, but it’s just another one of those things that the WordPress CMS has phased out over time, due to “security” issues.

      • Tyler June 11, 2011 at 7:31 pm - Reply

        Oh, I see what you mean now.

        I spent some time this afternoon tinkering with a variation on that snippet posted on and figured out how to make it work again on an independent WP installation, so hooray!

  2. KJ June 16, 2011 at 8:08 pm - Reply

    Here is my fix for this shortcut code in the functions.php file, in case it helps anyone…

    //Google Maps Shortcode
    function fn_googleMaps($atts, $content = null) {
    "width" => '490',
    "height" => '500',
    "src" => ''
    ), $atts));
    return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&output=embed"></iframe> <br /><a href="'.$src.'&source=embed" >View Larger Map</a>
    add_shortcode("googlemap", "fn_googleMaps");

    • SuperWaz June 17, 2011 at 7:05 pm - Reply

      Thanks, KJ.

  3. Artem May 23, 2012 at 2:37 pm - Reply

    Thanks. KJ!!!

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.