Last active
August 29, 2015 14:07
-
-
Save chrisblakley/0bf33b0975ef86053ee1 to your computer and use it in GitHub Desktop.
Allow for embedding Google Maps into your Wordpress posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_shortcode('map', 'map_shortcode'); | |
function map_shortcode($atts){ | |
extract( shortcode_atts(array("key" => '', "mode" => 'place', "q" => '', "center" => '', "origin" => '', "destination" => '', "waypoints" => '', "avoid" => '', "zoom" => '', "maptype" => 'roadmap', "language" => '', "region" => '', "width" => '100%', "height" => '250', "class" => '', "style" => ''), $atts) ); | |
if ( $key == '' ) { | |
$key = ''; //@TODO: Replace with your own key to avoid designating a key every time. | |
} | |
if ( $q != '' ) { | |
$q = str_replace(' ', '+', $q); | |
$q = '&q=' . $q; | |
} | |
if ( $mode == 'directions' ) { | |
if ( $origin != '' ) { | |
$origin = str_replace(' ', '+', $origin); | |
$origin = '&origin=' . $origin; | |
} | |
if ( $destination != '' ) { | |
$destination = str_replace(' ', '+', $destination); | |
$destination = '&destination=' . $destination; | |
} | |
if ( $waypoints != '' ) { | |
$waypoints = str_replace(' ', '+', $waypoints); | |
$waypoints = '&waypoints=' . $waypoints; | |
} | |
if ( $avoid != '' ) { | |
$avoid = '&avoid=' . $avoid; | |
} | |
} | |
if ( $center != '' ) { | |
$center = '¢er=' . $center; | |
} | |
if ( $language != '' ) { | |
$language = '&language=' . $language; | |
} | |
if ( $region != '' ) { | |
$region = '®ion=' . $region; | |
} | |
if ( $zoom != '' ) { | |
$zoom = '&zoom=' . $zoom; | |
} | |
return '<iframe class="nebula-googlemap-shortcode googlemap ' . $class . '" width="' . $width . '" height="' . $height . '" frameborder="0" src="https://www.google.com/maps/embed/v1/' . $mode . '?key=' . $key . $q . $zoom . $center . '&maptype=' . $maptype . $language . $region . '" style="' . $style . '"></iframe>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment