Stop WordPress from enclosing script in CDATA

心不动则不痛 提交于 2019-12-19 08:44:38

问题


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>

回答1:


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

wp-includes\post-template.php line 167




回答2:


You can also do in this way in template page file:

   <?php $content = str_replace(']]&gt;', ']]>', the_content()); echo $content; ?>


来源:https://stackoverflow.com/questions/8492472/stop-wordpress-from-enclosing-script-in-cdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!