admin管理员组文章数量:1336644
I am trying to display a google map using short code for a plugin I am building, but I can not get it to work. Does anyone have some advice on this? Here is my code:
add_shortcode( 'show_map', array('hotSpot', 'create_map'));
function create_map() {
?>
<script src=""></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(34.040819,-84.604660),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<?php
return '<div id="map_canvas"></div>';
}
I am trying to display a google map using short code for a plugin I am building, but I can not get it to work. Does anyone have some advice on this? Here is my code:
add_shortcode( 'show_map', array('hotSpot', 'create_map'));
function create_map() {
?>
<script src="https://maps.googleapis/maps/api/js"></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(34.040819,-84.604660),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<?php
return '<div id="map_canvas"></div>';
}
Share
Improve this question
asked Aug 14, 2014 at 18:00
ZachZach
531 silver badge3 bronze badges
2
|
1 Answer
Reset to default 1Based on what I can see, it looks like your calling the create_map function incorrectly.
add_shortcode() takes 2 parameters, the name of the shortcode and the function that gets rendered when called.
The array you are passing is how to call a method inside of a class. You're basically saying call the create_map method from the hotSpot class.
Assuming this code is not inside the hotSpot class - try this:
//change
add_shortcode( 'show_map', array('hotSpot', 'create_map'));
//to
add_shortcode( 'show_map','create_map');
Hope this helps!
本文标签: shortcodeExecuting Javascript in Plugin
版权声明:本文标题:shortcode - Executing Javascript in Plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742407788a2469179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
class
? – sakibmoon Commented Aug 14, 2014 at 18:24