How To Hide/Display Different Adsense Ads In Desktop & Mobile Depending On Screen Resolution

Google AdSense is Introduced the many Responsive Ads I Think you all are know that. but as long back to makes sure Ads is displayed depending on the screen resolutions. Here you will see the some Examples i will show you, When you can choose the responsive Ads, a 728×90 This is the leaderboard ad and this will be displayed in the desktop version and a very smaller 468×60 size banner to viewers on a tablet. But what if you have completely want to hide the ad?

Some many peoples and few newbie bloggers are also asked the various questions like “How to display different ads in desktop and mobile?”,  “How to display the AdSense ad only on desktop?” or  “How to display The AdSense ads only on the mobile?”. Well Friends i have also face the many times this problems and issues but i will decided this problems i will solution find him. So, Now Few months back and i will find the solution. So, Now I am sharing with the everyone now. This will probably solve the most of your problems.

How To Hide/Display Different Adsense Ads In Desktop & Mobile tablets

Different Ways To Achieve This:

Contents

Here are you will see the different types of methods in which you can solve this issue. You can go either with the WordPress plugin and use this all custom scripts.

Using WordPress Plugins

There are the many different plugins are available in this WordPress which will fulfill your need. You can use this plugins like Ad Inserter, Advanced Ads, etc. I am also used this plugin in few of my blogs. They have are the very effective, easy to use and you don’t need any technical knowledge to work with them.

Using CSS Media Queries

If you have at the good and basic of HTML & CSS knowledge are taking then if you have don’t face the any problems, this will be a piece of cake. Even if you are not, I’ll try to my best make if you have understand how it works.

Here’s the ad unit script when you create a new ad.

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

<ins class=”adsbygoogle”
style=”display:inline-block;width:336px;height:280px”
data-ad-client=”ca-pub-7525498198″
data-ad-slot=”6727986783″></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Hide AdSense Ad on mobile using CSS:

Here are you will see by making the some tweaks in thew above code, It will hide the ad in mobile and make it display only on desktop or tablet.

You can Create The CSS class and use this Media From CSS query, And considering the width of the screen into account. Here I have created you will see that a class of “hidead”, This will not display the any contents if the screen size and this is less than 480px.

But you can Add the same class to your AdSense code too. Which will make the code look like this:

<style>
@media (max-width: 480px) {
.hidead {
display: none !important;
}
}
</style>

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

<ins class=”adsbygoogle hidead”
style=”display:inline-block;width:336px;height:280px”
data-ad-client=”ca-pub-7525498198″
data-ad-slot=”6727986789″></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Note: You will Replace the publisher id and Text your own id  (data-ad-client) and adslot id (data-ad-slot) with your own AdSense IDs. 

Hide AdSense Ad on desktop or tablet using CSS:

This is the almost same process to the above case. But Here the only one changes you will see that you have to make in order to make it work. You can Replace the “max-width” in the CSS with “min-width”. This coding you will apply then This will not display the any ad if the screen size if more than 480px.

Here’s the code:

<style>
@media (min-width: 480px) {
.hidead {
display: none !important;
}
}
</style>

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

<ins class=”adsbygoogle hidead”
style=”display:inline-block;width:336px;height:280px”
data-ad-client=”ca-pub-7525498198″
data-ad-slot=”6727986789″></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Using Custom Java Script

I Think you will Understanding the all basics of javascript knowledge and this is the enough knowledge to deal with this method. Here, we are going to use the conditional tags to hide or display the ad units and this will fully depending on the screen resolution.

Hide AdSense Ad in mobile using custom script:

This ad code is the very pretty but much the same, here are we will be using the variable (td_screen_width) which we can defines the screen width. And we have write the condition and to display the ad code but according to our requirement Things.

Here is the code:

<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
<script type=”text/javascript”>
var td_screen_width = document.body.clientWidth;

if ( td_screen_width >= 468 ) {
/* large monitors */
document.write(‘<ins class=”adsbygoogle” style=”display:inline-block;width:300px;height:250px” data-ad-client=”ca-pub-75254981981XXXXX” data-ad-slot=”2626813281″></ins>’);
(adsbygoogle = window.adsbygoogle || []).push({});
}
</script>

Note: Replace the publisher id  (data-ad-client) and adslot id (data-ad-slot) with your own AdSense IDs.

Hide AdSense Ads in desktop or tablet using custom script:

Now, You will see Again, the code is similar to the above one. You just need change the value inside code and if condition. Check the below code:

<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
<script type=”text/javascript”>
var td_screen_width = document.body.clientWidth;

if ( td_screen_width < 468 ) {
/* Phones */
document.write(‘<ins class=”adsbygoogle” style=”display:inline-block;width:300px;height:250px” data-ad-client=”ca-pub-75254981981XXXXX” data-ad-slot=”4971251185″></ins>’);
(adsbygoogle = window.adsbygoogle || []).push({});
}
</script>

Use different AdSense Ads for mobile & desktop in the same location:

Now, You can also even use the two different ads codes for the mobile phone and desktop in the same location.

Here is the code:

<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
<script type=”text/javascript”>
var td_screen_width = document.body.clientWidth;

if ( td_screen_width >= 468 ) {
/* large monitors */
document.write(‘<ins class=”adsbygoogle” style=”display:inline-block;width:468px;height:15px” data-ad-client=”ca-pub-75254981981XXXXX” data-ad-slot=”3494921416″></ins>’);
(adsbygoogle = window.adsbygoogle || []).push({});
}

if ( td_screen_width < 468 ) {
/* Phones */
document.write(‘<ins class=”adsbygoogle” style=”display:inline-block;width:200px;height:90px” data-ad-client=”ca-pub-75254981981XXXXX” data-ad-slot=”4972194885″></ins>’);
(adsbygoogle = window.adsbygoogle || []).push({});
}
</script>

 This all above code are implementations you should help you in this majority types of cases. Do let me know if you have feel the any more doubts and Queries in your mind then you can freely comments below and we would be happy to help you. I hope you are like this article How To Hide/Display Different Adsense Ads In Desktop & Mobile, Tablets Etc. Keep visits again 🙂 for more cool stuffs, tricks and Information. 🙂

Related Post:

Comments

  1. Dhirendra Kumar Rai says

    Hello Sir,
    I want to hide my (A-ads) Banner ads from Desktop & Tablet mode.
    Can you tell if this will possible or not.

  2. Are you sure that changing the Adsense Code is allowed? 🙂

Speak Your Mind

*

error: Don\'t Copy, Sorry For That :)