Skip to content Skip to sidebar Skip to footer

How To Hide Div When Containing A Google Adsense Advert?

I have a div that contains an adsense ad. However I want to remove the div if a class is present.
... adsense ad ...
$(document).ready(funct

Solution 1:

$('.back:visible').remove();

Using CSSdisplay:none you can't remove it, you just hide it.

If you using $('.back:visible').hide()/$('.back:visible').css('display', 'none');

you can using $('.back:visible').show() to show it. But via .remove(), you can't show it again.

Solution 2:

Don’t change the Google Adsense snippet!

According the Google Adsense terms of service it’s not allowed to manipulate their code snippet. It’s also not allowed to show ads through an IFRAME or to use JavaScript and Ajax to show or hide Adsense ads. But it’s allowed to exclude the whole Adsense snippet whenever you like. Another option is to use some ad server like DoubleClick for Publishers, DFP is a free Google service and I read somewhere that there is an option to filter ads for specific countries too.

Put div around Google ads like given below:

<divid="GoogleAds1"><scripttype="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxx";
google_ad_host = "pub-xxxxxxxxxxxxxxx";
/* 300x250, created 1/31/10 */
google_ad_slot = "xxxxxxxxxx";
google_ad_width = 300;
google_ad_height = 250;
//--></script><scripttype="text/javascript">
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
</script></div><scripttype="text/javascript">varAds1 = document.getElementById('GoogleAds1');

Ads1.parentNode.removeChild(Ads1);

</script>

Add javaScript at the end of your post and your Google ads will be hide from that particular post.

So heres your all answers which you wanted to know

Solution 3:

Apparently it is allowed to use this code:

<style>
  .responsive-test { display: block;}
  @media(max-width: 480px) { .responsive-test { display: none; } }
</style><scriptasyncsrc="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Resposive_TEST --><insclass="adsbygoogle responsive-test"data-ad-client="ca-pub-3086914080036003"data-ad-slot="1408862175"data-ad-format="auto"></ins><script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

I posted more info in my topic: Remove adsense on mobile

Solution 4:

This article helped me. Basically it describe how you can use CSS code to hide div containing 'google-auto-placed' class from specific area of your website page.

For my particular wordpress website I was having auto ads getting placed by google script in website navigation link, which was very irritating. So I tried below piece of CSS code on my theme style sheet and it WORKED! atleast for me.

.ht-middle-header.google-auto-placed {
    display:none;
}

Article link: https://letstechready.com/2022/01/how-to-hide-google-ads-from-specific-area-of-your-website.html

Solution 5:

Here you're mentioned that you want to remove the adsense add from your html(I want to remove the div is a class is present.).

Whereas using css you can't remove html elements, only it can be hidden using (display: none / visibility: hidden).

So it depends upon your wish, if you want to remove then you have to use js/jQuery otherwise simply hide using css.

Post a Comment for "How To Hide Div When Containing A Google Adsense Advert?"