Close

Google Adsense

richardbautista
3 years ago
#11911 Quote
Avatar
  • 2
Will Google Adsense work if it is placed inside a html widget? 
hristian.dimov
3 years ago
#11952 Quote
Avatar
  • Moderator
  • 386
richardbautista wrote:
Will Google Adsense work if it is placed inside a html widget? 


Hi Richard,

You may try to wrap the javascript code with CDATA. Here is an example: https://www.nop-templates.com/boards/topic/2483/how-do-i-include-a-script-in-a-tab-

Hope this helps!
Regards,
Hristian Dimov
Nop-Templates.com
richardbautista
3 years ago
#11953 Quote
Avatar
  • 2
Thank you for the reply! 

I am not really a coder so it may be difficult for me to digest the thread you suggested. 

Say below is the code I get from Google Adsense, how do you go about it:L

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- SAL-e, Bottom Banner -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-8453972048291109"
     data-ad-slot="4726471878"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
hristian.dimov
3 years ago
#11956 Quote
Avatar
  • Moderator
  • 386
richardbautista wrote:
Thank you for the reply! 

I am not really a coder so it may be difficult for me to digest the thread you suggested. 

Say below is the code I get from Google Adsense, how do you go about it:L

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- SAL-e, Bottom Banner -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-8453972048291109"
     data-ad-slot="4726471878"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>


Hi Richard,

You may try with this:

<!-- SAL-e, Bottom Banner -->
<div id="google-ads"></div>
<script>// <![CDATA[
(function() {
    var script = document.createElement("script");
    script.src = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
  script.async = true;
    document.body.appendChild(script);
  
  var ins = document.createElement("ins");
  ins.class = "adsbygoogle";
    ins.style = "display:inline-block;width:728px;height:90px";
  ins.setAttribute("data-ad-client", "ca-pub-8453972048291109");
  ins.setAttribute("data-ad-slot", "4726471878");
  
  var googleAds = document.getElementById("google-ads")
    googleAds.appendChild(ins);
  
  (adsbygoogle = window.adsbygoogle || []).push({});
})();
// ]]></script>


but I'm not sure that it will work. When you create an HTML Widget, you need to paste the code above into Tools -> Source code form as otherwise the code will not be executed.

Hope this helps!
Regards,
Hristian Dimov
Nop-Templates.com