On a page in WordPress, If I enter the following code:
var r="<li><a href="#"><img src="" + slide.src + '" width="50" height="50" /></a></li>';
it is rendered in the browser as
var r="
<li><a href="#"><img src="" + slide.src + '" width="50" height="50" /></a></li>
';
and it gives me this error in FF Console SyntaxError: unterminated string literal var r="
This is a single-user blog, so I am “Administrator”.
How do I prevent WordPress from fouling my code?
4 Answers
In the new WordPress (WP 5+) Editor – Gutenberg, you can use a “Custom HTML” block to prevent the automatic line breaks and paragraphs:
on Visual Editor click + > Formatting > Custom HTML – and put your JavaScript in there
on Code Editor enclose your JavaScript with <!-- wp:html --> <!-- /wp:html -->