Prevent WordPress from adding linebreaks to javascript embedded in a page

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 -->

Leave a Comment