Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
Wordpress (quick n' dirty) shortcode to display a map and markers.
This shortcode display a google map with some markers on it.
<!--Usage :-->
Somewhere###<strong></strong><br /><a href=""###-25.363882,174.044922
Somewhere else###<strong></strong><br /><a href=""###15.549876,131.123489
function amod_sc_googlemap( $atts , $content = null ) {
$markers = '';
foreach(explode("\n", str_replace("\r", "\n", $content)) as $k=>$place) {
$place = trim($place);
if(!empty($place)) {
list($name, $info, $coord) = explode(AMOD_SC_GOOGLEMAP_SEPARATOR, $place);
$markers .= 'var infowindow'.$k.' = new google.maps.InfoWindow({content: "'.$info.'"});'."\n".
'var marker'.$k.' = new google.maps.Marker({ position: new google.maps.LatLng('.$coord.'), map: map, title: "'.$name.'"});'."\n".
'google.maps.event.addListener(marker'.$k.', "click", function(){ infowindow'.$k.'.open(map, marker'.$k.'); });'."\n\n";
return '<div id="map-canvas" style="width:430px;height:450px;"/>
<script src=";sensor=false&amp;language=fr&amp;region=fr" type="text/javascript"></script>
<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(10, -10),
zoom: 1
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
google.maps.event.addDomListener(window, "load", initialize);
add_shortcode( 'amod-map', 'amod_sc_googlemap' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment