Different Ads for Mobile and Desktop Via Adsense

Hi,
I want to display two different types of ads for mobile and desktop users. Following is the case.

For Desktop: 728x90 and for Mobile: Squre 300px

If I am using responsive design, for desktop it shows 300PX tall ads and not 90px tall.

I am using this article of @GulshanKumar to lazyload ads - https://gulshankumar.net/setup-lazy-loading-google-adsense-ad-units/.

Please help with the same.

Thanks & Regards,

Your code will goes like this

<style>
.example_responsive_1 { width: 300px; height: 250px; }
@media(min-width: 800px) { .example_responsive_1 { width: 728px; height: 90px; } }
</style>
<!-- example_responsive_1 -->
<ins class="adsbygoogle example_responsive_1"
     style="display:inline-block"
     data-ad-client="ca-pub-XXXXXXX11XXX9"
     data-ad-slot="8XXXXX1"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

As suggested in AdSense Help Center

1 Like

Thanks, I will update the code and also update about the outcome. So that others can use the same.

PS: I have implemented the above code and it is working perfectly.

2 Likes

There is option in Ad inserter pulgin setting to select device to show ads.

1 Like

Use manual coding instead of plugins to make your site faster.

1 Like

This is not an efficient method to load ad on different device, it just hide desktop ad won’t stop it from loading. I suggest:

<?php if ( wp_is_mobile() ) : ?>

/* Display and echo mobile specific stuff here */

<?php else : ?>

/* Display and echo desktop stuff here */

<?php endif ; ?>

1 Like
  • AdSense first check insertion size before serving advt. In background, It doesn’t load Desktop advt in mobile. Try resizing screen to check.

  • PHP method will require separate mobile caching.

Sorry! I misinterpreted his message. I thought he want different code for different devices.

It’s okay!!
Thanks for clarifying.