Home / functions.php / Google maps shortcode
  • How to 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.

    ( click code to copy )

    wordpress snippet : PHP - functions.php

    function fn_googleMaps($atts, $content = null) {
                        "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");
    ( click code to copy )

    wordpress snippet : SHORTCODE

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

    ( WordPress codex functions, hooks, in this snippet. )

    add_shortcode, shortcode_atts,
  • 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.

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