Skip to content

Instantly share code, notes, and snippets.

@Yelakelly
Last active March 1, 2016 16:31
Show Gist options
  • Save Yelakelly/7800c8e2b5daff3107ff to your computer and use it in GitHub Desktop.
Save Yelakelly/7800c8e2b5daff3107ff to your computer and use it in GitHub Desktop.
Wordpress Shortcode - YandexMap
function yandex_map($args){
$height = empty($args['height']) ? "400" : $args['height'];
return "
<div id='map' style='width: 100%; height: {$height}px'></div>
<script src='//api-maps.yandex.ru/2.1/?lang=ru_RU' type='text/javascript'></script>
<script>
ymaps.ready(init);
function init () {
var myMap = new ymaps.Map('map', {
center: [{$args['x']},{$args['y']}],
zoom: 16,
controls: ['zoomControl']
}),
myPlacemark = new ymaps.Placemark([{$args['x']}, {$args['y']}]);
myMap.geoObjects.add(myPlacemark);
myMap.behaviors.disable('scrollZoom');
}
</script>";
}
add_shortcode('yandex-map','yandex_map');

Wordpress Shortcode - YandexMap.

Add YandexMap on the page.

Settings:

  • x - longitude
  • y - latitude
  • height - height of map (Default: 400px)

Usage:

[yandex-map x="32.2" y="48.2" height="400"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment