AdSense Fix after WordPress 4.1 Upgrade
-
I upgraded to WordPress 4.1 a few days ago. The next day I was trying to add a new AdSense ad to one of my pages and it wouldn’t display at all even though previous ads were showing fine. I was pulling my hair out but yesterday I finally figured out what the problem was. So if you’re experiencing it as well, here’s how I fixed it.
When you grab the code from AdSense, it looks like this:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- Ad Unit Name --> <ins class="adsbygoogle" style="display:inline-block;width:300px;height:250px" data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" data-ad-slot="xxxxxxxxxx"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>
To get it to display, I removed the line breaks in the “ins” tag so the code looks like this now:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- Ad Unit Name --> <ins class="adsbygoogle" style="display:inline-block;width:300px;height:250px" data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" data-ad-slot="xxxxxxxxxx"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>
This change is only required when the ad is within the body of a post or page. It works fine as is in my widgets and in my functions.php file.
[Unrelated question: Is there a way to search JUST the forums and not all of www.ads-software.com? I wanted to see if I could find any other threads about this issue but mostly got a list of plugin pages.]
- The topic ‘AdSense Fix after WordPress 4.1 Upgrade’ is closed to new replies.