我正在使用 WordPress 的 HTML 导入插件导入 HTML 页面。

我有一个谷歌 map 的代码片段,它是导入的。

但是,在导入之后,它将 script 标签包含在 CDATA 中。如果我删除 CDATA, map 工作正常。如何阻止 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>

最佳答案

$content = str_replace(']]>', ']]&gt;', $content);

wp-includes\post-template.php 第 167 行

关于html - 阻止 WordPress 在 CDATA 中包含脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8492472/

10-13 00:12