I have a php page with JavaScript to be used on a wordpress page,but when the page is generated all <div>
<p>
etc. appends new lines. Example :
Test.php ->
<script type="text/javascript">
alert('hello<div>world</div>');
</script>
When I view-source there is new lines on each html-tags : ‘div’ – which breaks the JavaScript syntax
I really don’t get it
Thanks
This is a feature of WordPress called
wpautop
. It will insert<br>
and<p>
tags automatically, depending on the number of newlines you use in your editor. You can disable this globally by creating a new plugin with this single line of code. (Or, alternatively, put this in your themesfunction.php
)However, this might break other pages, so minifying your Javascript into a single line is probably the better alternative.