Making Google Adsense more responsive

Hello,

I placed my adsense code in my functions folder and got it to work but now am trying to make it responsive and am running into a problem. I placed the following under additional functions in my child theme’s functions folder. When I use this code there is no ad on the site:

// Google Adsense
add_action( 'wp_head', 'add_head_script' );
function add_head_script(){
?>
<div align="center">
<style>
.homepage_banner { width: 320px; height: 100px; }
@media(min-width: 500px) { .homepage_banner { width: 468px; height: 60px; } }
@media(min-width: 800px) { .homepage_banner { width: 728px; height: 90px; } }
</style>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- .homepage_banner -->
<ins class="adsbygoogle .homepage_banner"
     style="display:inline-block"
     data-ad-client="ca-pub-XXXXXXXXXXXXX"
     data-ad-slot="XXXXXXXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<?php
}

The following works but without the responsiveness:

// Google Adsense
add_action( 'wp_head', 'add_head_script' );
function add_head_script(){
?>
<div align="center">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sugarfree Gallery Main Page -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-XXXXXXXXXXXXX"
     data-ad-slot="XXXXXXXXXX"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<?php
}

Thanks!!!

(credentials in secure note)

Hello @gebigoma,

Thanks for asking. :slight_smile:

I suggest you to please refer following resources to setup Responsive Google Ads as it falls outside the scope of the support we offer.




Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.