Stop WordPress from enclosing script in CDATA

2019-02-18 23:16发布

问题:

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; ?>