4

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>
vzwick
  • 11,008
  • 5
  • 43
  • 63
user1009059
  • 75
  • 1
  • 3

2 Answers2

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

wp-includes\post-template.php line 167

Badr Hari
  • 8,114
  • 18
  • 67
  • 100
  • should I comment this line ? This is adding closing brackets , where are opening brackets being added ? – user1009059 Dec 13 '11 at 23:38
  • 1
    Thanks for the help Badri , I found the solution on line 167 by changing code to this : wp-includes\post-template.php line 167 $content = str_replace('<![CDATA[','',$content); $content = str_replace(']]>','',$content); //$content = str_replace(']]>', ']]>', $content); – user1009059 Dec 13 '11 at 23:47
  • Mhh, sorry for my minimalist answer, I thought I wrote it more clear. Don't forget to change it every time you upgrade Wordpress. Or write it somehow to your functions.php theme file. – Badr Hari Dec 14 '11 at 15:57
  • 1
    Ugh. Don't *ever* overwrite WP core files. – vzwick Apr 20 '15 at 15:01
0

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

   <?php $content = str_replace(']]&gt;', ']]>', the_content()); echo $content; ?>
disinfor
  • 10,865
  • 2
  • 33
  • 44