在wordpress中使用短代码时,Javascript将不起作用

在wordpress中使用短代码时,Javascript将不起作用,javascript,wordpress,plugins,Javascript,Wordpress,Plugins,我制作了一个插件,它使用Java脚本制作谷歌地图。插件在管理页面上功能齐全。当我使用一段短代码在常规页面上为前端用户显示插件时,JavaScript不起作用了吗 其他一切都可以工作,选择框和数据库中动态显示的内容表,但是我用于地图的java脚本不起作用 我没有使用jquery或任何$,所以我不知道为什么会出现这种情况。谢谢 <script src="https://maps.googleapis.com/maps/api/js" type="text/javascript">&l

我制作了一个插件,它使用Java脚本制作谷歌地图。插件在管理页面上功能齐全。当我使用一段短代码在常规页面上为前端用户显示插件时,JavaScript不起作用了吗

其他一切都可以工作,选择框和数据库中动态显示的内容表,但是我用于地图的java脚本不起作用

我没有使用jquery或任何$,所以我不知道为什么会出现这种情况。谢谢

<script src="https://maps.googleapis.com/maps/api/js"   type="text/javascript"></script>
 <script type="text/javascript">
 //<![CDATA[
                                geocoder = new google.maps.Geocoder();
                                //function for retrieving coordinates
                                function getCoordinates (address, callback){
                                    var coordinates;
                                    geocoder.geocode({address:address},    function (results, status){
                                        coords_obj=   results[0].geometry.location;
                                        coordinates =   [coords_obj.k,coords_obj.D];
                                        callback(coordinates);
                                    })
                                }


                                var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
                                    new google.maps.Size(32, 32), new google.maps.Point(0, 0),
                                    new google.maps.Point(16, 32));
                                var center = null;
                                var map = null;
                                var currentPopup;
                                var bounds = new google.maps.LatLngBounds();
                                function addMarker(lat, lng, info) {
                                    var pt = new google.maps.LatLng(lat, lng);
                                    bounds.extend(pt);
                                    var marker = new google.maps.Marker({
                                        position: pt,
                                        icon: icon,
                                        map: map
                                    });
                                    var popup = new google.maps.InfoWindow({
                                        content: info,
                                        maxWidth: 500

                                    });
                                    google.maps.event.addListener(marker, "click", function() {
                                        if (currentPopup != null) {
                                            currentPopup.close();
                                            currentPopup = null;
                                        }
                                        popup.open(map, marker);
                                        currentPopup = popup;
                                    });
                                    google.maps.event.addListener(popup, "closeclick", function() {
                                        map.panTo(center);
                                        currentPopup = null;
                                    });
                                }
                                function initMap() {
                                    //retrives coordinates from address - not the best practice but it works for now
                                    getCoordinates('<?php echo $paddress ?>', function(coords){

                                        // centers map based on coordinates of the address
                                        map = new google.maps.Map(document.getElementById("map"), {
                                            center: new google.maps.LatLng(coords[0], coords[1]),
                                            zoom: 9,
                                            mapTypeId: google.maps.MapTypeId.ROADMAP,
                                            mapTypeControl: false,
                                            mapTypeControlOptions: {
                                                style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
                                            },
                                            navigationControl: true,
                                            navigationControlOptions: {
                                                style: google.maps.NavigationControlStyle.SMALL
                                            }
                                        });
                                        // paitents Address marker
                                        var pmarker = new google.maps.Marker({position:new google.maps.LatLng(coords[0], coords[1]), title:"Paitents Address!"});
                                        pmarker.setMap(map);
                                        // adds markers on map from database based on specialist and insurance by lat and long
                                        <?php
                                        $query = "SELECT * FROM $specialist WHERE $insurance=1 AND is_active=1";
                                        $result = mysql_query($query);
                                        while ($row = @mysql_fetch_assoc($result)){
                                        $name=$row['provider'];
                                        $lat=$row['lat'];
                                        $lon=$row['lon'];
                                        $address=$row['address'];
                                        $phone = $row['phone'];
                                        $fax = $row['fax'];
                                        echo ("addMarker($lat, $lon,'<p><b>$name</b><br/>$address<br/>Phone:$phone<br/>Fax:$fax<br/></p>');\n");
                                        }
                                        ?>
                                        center = bounds.getCenter();

                                    })
                                }
                                //]]>
                            </script>

//
center=bounds.getCenter();
})
}
//]]>

很难找到代码的问题并给出解决方案,无法查看!当我构建这个插件时,我将所有javaScript与html标记一起放在一个包含的php文件中。由于这是一个插件,我是否还需要在我的主插件php文件中创建一个函数来排队并注册脚本,就像在word press主题中一样,以便Javascript工作?是的,最好将Javascript保存在单独的文件中,并在插件主文件中使用wp_enqueue_脚本。