WordPress <![CDATA[ comments out my JavaScript

I’m attempting to add a short script in the page editor, but WordPress automatically adds CDATA tags to it. As I understand it that’s usually fine, but I’ve been having an issue. I have it currently looking like this:

<script>// <![CDATA[
<!--
  Some script here.
// -->
//]]>
</script>

The problem I keep running into is that since it’s all on one line when the page is loaded, the // before the [CDATA[ ends up commenting out my whole script and it never runs. Why would this happen and how can I prevent it? Any advice is greatly appreciated!

Related posts

1 comment

Comments are closed.