WordPress: inserire le Google Maps con uno shortcode

Uno shortcode di WordPress per inserire le Google Maps sul nostro sito.

WordPress di Gabriele Romanato

Possiamo includere le Google Maps nel nostro sito utilizzando uno shortcode di WordPress che accetta come parametri le dimensioni e l'URL della mappa. Vediamo come fare.

Aggiungete il seguente codice al file functions.php:


function add_google_maps($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", "add_google_maps");

Esempio d'uso:

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