Mediante el siguiente código podemos añadir un mapa de Google Maps con un marcador a través de shortcodes. Primero debemos solicitar una Key en http://code.google.com/intl/es/apis/maps/signup.html. Luego insertamos el siguiente código en nuestro archivo functions.php
function googlemap_shortcode( $atts ) {
extract(shortcode_atts(array(
'width' => '500px',
'height' => '300px',
'apikey' => 'REPLACEME',
'marker' => '',
'center' => '',
'zoom' => '13'
), $atts));
if ($center) $setCenter = 'map.setCenter(new GLatLng('.$center.'), '.$zoom.');';
if ($marker) $setMarker = 'map.addOverlay(new GMarker(new GLatLng('.$marker.')));';
$rand = rand(1,100) * rand(1,100);
return '
<script src="http://maps.google.com/maps?file=api&v=2.x&sensor=false&key='.$apikey.'" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas_'.$rand.'"));
'.$setCenter.'
'.$setMarker.'
map.setUIToDefault();
}
}
initialize();
</script>
';
}
add_shortcode('googlemap', 'googlemap_shortcode');En el shortcode pasaremos los parámetros zoom, center, marker y width de la siguiente manera:
[googlemap zoom="13" center="52.66389056542801, 0.1641082763671875" marker="52.66389056542801, 0.1641082763671875" width="488px"]
y el resultado:
Visto en blue-anvil
Emprendedora incansable, fundadora de SummArg y de SiteFun.