阻止 WordPress 将脚本包含在 CDATA 中
我正在使用 WordPress 的 HTML 导入插件导入 HTML 页面。
我有一个谷歌地图的代码片段,它是导入的。
但是,导入后,它会将 script
标记包含在 CDATA
中。如果我删除 CDATA,地图就可以正常工作。如何阻止 WordPress 将脚本包含在 CDATA 中?
这是脚本:
<script type="text/javascript">
<[[CDATA[
var locations = [ ['<strong>Alabama', 33.606379, -86.50249, 1] ];
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 5,
center: new google.maps.LatLng(33.606379, -86.50249),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, click, (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
]]>;
</script>
I am importing HTML pages using HTML import plugin for WordPress.
I have a code snippet for google maps, which is imported.
However, after import, it encloses the script
tag in CDATA
. If I remove CDATA, the map works fine. How do I stop WordPress from enclosing the script with CDATA?
Here's the script :
<script type="text/javascript">
<[[CDATA[
var locations = [ ['<strong>Alabama', 33.606379, -86.50249, 1] ];
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 5,
center: new google.maps.LatLng(33.606379, -86.50249),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, click, (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
]]>;
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
wp-includes\post-template.php 第 167 行
wp-includes\post-template.php line 167
您也可以在模板页面文件中这样做:
You can also do in this way in template page file: