Fixing Adsense Not Displaying (In Wordpress)

Recently a client was having issues with Adsense units not displaying on their WordPress blog. All the usual troubleshooting steps didn’t reveal anything, and the problem was made even more confusing by the fact that ads would display in the sidebar, while the exact same ad unit in the content section wouldn’t show at all.

It seemed that the only difference was that ads the client had added themselves as widgets through the WordPress admin interface would show, while ads I had added by editing raw HTML files on the web server would not, despite the fact that the code was exactly the same.

Or was it?

Code == Code?

Somehow when the client had sent me their Adsense code, the “indenting” spaces had been converted to no-break spaces (UTF-8 0xc2a0), so in Vim, everything seemed to be fine.

After many hours of frustration and trying different ad units, the solution was simple: remove the “bad” spaces.

Before

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

(lines 4-6 have the bad spaces at the start)

After

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

This was incredibly frustrating because of the number of variables when dealing with Adsense. For example, if your account or ad unit is new it might not be serving ads yet, or depending on the placement of the unit or number of other units on the page it may be blank. The frustration was expounded after working out how simple a fix this was.

Showing Them Characters

Your text editor should be configured to show invisibles. I found this simple guide to making Vim highlight “suspicious” characters very useful. TL;DR: add this to your vimrc:

set listchars=nbsp:¬,eol:¶,tab:>-,extends:»,precedes:«,trail:•
set list

Conclusion

Showing invisible characters will probably save you time.

Previous entry

Next entry