JS code in HTML widgets causing sidebars to not load
-
I had a couple of display ad codes (Google AdSense and another) in HTML widgets and noticed that the sidebars were not loading or loading long after the main content are (home and category pages) have loaded. Didn't know why until I deleted the HTML widgets.
Not the sidebars load as expected.
The other part of the ads were not showing in the sidebars.
So that looks like 2 issues.
-
JS code in HTML widgets affecting the loading of the sidebars
-
JS code not workig in HTML widgets.
-
-
What code did you put into the sidebar? If one widget crashes then I could see the others going down with them as well
-
Here's a real sample:
<script type="text/javascript"><!-- google_ad_client = "ca-pub-8440766493813069"; /* 300x250 Post Left July 1 2012 */ google_ad_slot = "9205608781"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
That, btw, is the script for a Google Adsense ad. It's never rendered.
-
Let me know if this works for you:
<div id="adsense-container"></div> <script type="text/javascript"> document.write = function(str) { console.log(str); $('#adsense-container').html(str) }; </script> <script type="text/javascript"><!-- google_ad_client = "ca-pub-xxx"; google_ad_slot = "xx"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
I couldn't test it because I don't think you gave me the right ad ID's and such. BTW, there is a new adsense plugin by @dove which should be a lot more flexible than this widget
-
Ok, I just updated the previous post with the complete Google ad code. See if ti works for you.
About @dove's GA code, it works in-post and for the footer and header area, not in the sidebars. Bu even at that, it's still a little bit buggy.
I'll test the code you provided.
-
yup, worked on my end. here's the final:
<div id="adsense-container"></div> <script type="text/javascript"> document.write = function(str) { console.log(str); $('#adsense-container').html(str) }; </script> <script type="text/javascript"><!-- google_ad_client = "ca-pub-8440766493813069"; /* 300x250 Post Left July 1 2012 */ google_ad_slot = "9205608781"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
This will only work for one adsense snippet per page. If you want more I can always tweak it around for you
-
Thanks. Since I use other display ad providers other than Google, it'd be better to have something that's ad provider agnostic and that will work if more than one such widgets are used. I expect to have 3 of those in the sidebar.
I'm only using Google code as an example, but don't intend to run Google ads on the sidebar.
-
<script type="text/javascript"> document.write = function(str) { document.adcounter = document.adcounter ? (document.adcounter + 1) : 0 $('#ad-container-' + document.adcounter).html(str) }; </script> <div id="ad-container-0"></div> <script type="text/javascript"><!-- google_ad_client = "ca-pub-8440766493813069"; /* 300x250 Post Left July 1 2012 */ google_ad_slot = "9205608781"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
For each advertisement widget on the page, increase the id by 1:
<div id="ad-container-0"></div> ... <div id="ad-container-1"></div> ... etc
Let me know if this does the trick and maybe I'll publish it as a gist for anybody else who runs into the same issue
-
Something's not kosher, but I'll wait until I'm running the latest code before comment further on this.
-
Ok, the Google ad will not show on the home page or category page, only on topic pages. Scripts from another ad provider does not work and the side will not load. The HTML widget, me thinks, should be able to render any HTML/JS script.