How to prevent Shopify adding unwanted html in page editor

New Member
2 0 0

Hi! I'm attempting to create an order tracking page for my store. I have the code set up and it works. Or I should say it worked...

For some reason shopify started putting the following code into the text editor every time I save: // <![CDATA[

I take that code out, but when I click save, Shopify enters it back automatically. I'm not clicking back to the visual editor either. When I hit the save button, Shopify inputs the "cdata" code then automatically switches back to the visual editor. 

It's strange because it didn't do this at first. I was able to save and the order tracking page worked fine. Here's the code I'm trying to put on the page in html:

<script type="text/javascript">
function changeText2(){
    var userInput = document.getElementById('userInput').value;
    var lnk = document.getElementById('lnk');
    lnk.href = "" + userInput;
    window.location = lnk.href;
<input type="text" id="userInput" placeholder="Enter Tracking # Here" /> <input type="button" value="TRACK" onclick="changeText2()" />

The following article started to answer the question, but it got stranded:

So what can I do to prevent Shopify auto editing my code like this?


Shopify Expert
9800 91 1553

The Shopify RTE (Rich Text Editor) will try and correct formatting issues, close tags, etc. Right now it also adds CDATA wrappers around scripts too. Out of interest, what's the problem with the CDATA tags being added? Is something breaking?

If you must 100% not have that code added look into:

  • using an alternate template with that code hard coded in,
  • or modify the template to add a conditional statement to toggle when it shows
  • or add the script into your main JS file.
★ Winning Partner of the Build a Business competition. ★
New Member
2 0 0

Hey thanks for the reply. Yes it breaks the script with that code added in. I click the button and basically nothing happens. The script doesn't fire.

Not really a coder but I'll look further into some of the suggestions you made.

Just as an extra bit of info Shopify adds the cdata code in a weird spot after the JavaScript opening. Not sure if that makes sense or not but I think it's part of what's breaking things

New Member
1 0 0

Just ran into this problem with a client. They'd like to be able to add scripts to generic pages that are stored in the content field of the page. Unfortunately one of the tags is of type text/x-jsrender (“<script id="mediaTemplate" type="text/x-jsrender">), and these CDATA tags break the template in the script every time they click save.