Multiple Google AdSense ad blocks on same page are causing error 400 Bad Response

When trying to include multiple Google AdSense ad blocks using the code provided by Google on the same page you will likely get a 400 Bad Response error.

This is caused by including adsbygoogle.js multiple times:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

Thus, simply include adsbygoogle.js only once and use the ad generation code where applicable:

<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="XYZ"
     data-ad-slot="XYZ"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Hint: When using WordPress and custom themes you can simply add the required Adsense JS file adsbygoogle.js using the following code in your theme’s functions.php file:

function add_google_adsense_js() {
    wp_enqueue_script( 'google_adsense_js', '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js');
}

add_action( 'wp_enqueue_scripts', 'add_google_adsense_js' ); 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *