Google adsense JS ads are not working in TinyMCE editor?

4 posts by 3 authors in: Forums > CMS Builder
Last Post: September 4, 2019   (RSS)

By (Deleted User) - August 16, 2019

I am using TinyMCE text editor. I want to add AdSense code in the blog post but when I add AdSense JS ad code in source code(TinyMCE source code) it converts into HTML like this -

I add this JS code in TinyMCE source code-

<scriptasyncsrc="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><insclass="adsbygoogle"style="display:block;text-align:center;"data-ad-layout="in-article"data-ad-format="fluid"data-ad-client="ca-pub-206XXXXXXXXX"data-ad-slot="3413807300"></ins><script>(adsbygoogle = window.adsbygoogle ||[]).push({});</script>

TinyMce converts this JS ad code to -

<p><script></script></p><p></p><p><script>// <![CDATA[(adsbygoogle = window.adsbygoogle ||[]).push({});// ]]></script>

How to add AdSense ads code in TinyMCE with some JS code. I don't want convert source code to HTML etc like this.

By daniel - August 16, 2019

Hi Vishal,

There's no easy way to override the HTML formatting that happens in the WYSIWYG fields, though in general, they're not ideal for inserting things like JavaScript. My recommendation would be to add a new text field or text box specifically for this adsense code. Text fields and text boxes should both keep your JS intact.

Let me know if you have any other questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By moh3 - September 4, 2019 - edited: September 4, 2019

You need to add a wysiwyg_custom.php

and add the following option in tinymce init function

extended_valid_elements:"body[style|script|iframe],"
+"p[script|div|p|br|span|img|style|h1|h2|h3|h4|h5|iframe|hr|class],"
+"div[script|p|br|span|img|style|h1|h2|h3|h4|h5|iframe|i|hr|class],"
+"iframe[align|longdesc|name|width|height|frameborder|scrolling|marginheight|marginwidth|src|id|class|title|style|allowfullscreen],"
+"span[h1|h2|img|i|data|style|class],"
+"i[h1|h2|img|span|data|style|class],"
+"javascript[src|async],"
+"ins[class|style|data],"
+"img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style|placeholder_data]",
valid_children:"+body[style|script|iframe],"
+"+p[script|div|p|br|span|img|style|h1|h2|h3|h4|h5|iframe|hr|class],"
+"+div[script|p|br|span|img|style|h1|h2|h3|h4|h5|iframe|i|div|hr|class],"
+"+iframe[align|longdesc|name|width|height|frameborder|scrolling|marginheight|marginwidth|src|id|class|title|style|allowfullscreen],"
+"+span[h1|h2|img|i|data|style|class],"
+"i[h1|h2|img|span|data|style|class],"
+"javascript[src|async],"
+"ins[class|style|data],"
+"+img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style|placeholder_data]",