10

I have a problem in a project where an AdSense Auto Ad code has been pasted, one of the ads automatically placed have ruined the web page layout and design. Is there a method to prevent a specific ad to be shown inside a certain element or a container. Here is a sample of what the ad has done:

Code before AdSense Auto Ad was implimented:

 <div class="row">
  <div class="col-md-4">
   somecontent
  </div>
  <div class="col-md-4">
   somecontent
  </div>
  <div class="col-md-4">
   somecontent
  </div>

Code after AdSense Auto Ad was implimented:

 <div class="row">
  <div class="col-md-4">
   somecontent
  </div>
  <div class="google-auto-placed">
    ad content
  </div>
  <div class="col-md-4">
   somecontent
  </div>
  <div class="col-md-4">
   somecontent
  </div>
Surya Neupane
  • 906
  • 10
  • 20

4 Answers4

7

My solution for this problem is only with CSS. If I don't want to display auto placed google ad in specific container then I add some class to that container, e.g. "no-ads".

Then my CSS is simple:

.no-ads .google-auto-placed {
   display: none !important;
}
drazewski
  • 1,739
  • 1
  • 19
  • 21
  • Thanks. I don't know if it's just me but after I used this approach adsense doesn't insert the ads anymore in that location. When I remove the "no-ads" class it inserts them again – QuantumBlack Jul 21 '23 at 09:25
4

I just found an easier way to do this.

You should go :

  • Sign in to your AdSense account.
  • Click Ads.
  • On the "Auto ads" page, under "Global settings", click edit Edit button.

Here you can see how would google generate the auto ads in specific page. you can also hit a remove button on the ad it self.

jony89
  • 5,155
  • 3
  • 30
  • 40
  • Also, you may need to set the Ad Load to Max to see an ad in the area that spoils your layout. The preview has to show an ad in that position before you can remove it. – EamonnM Oct 29 '20 at 11:41
2

You could try to make a JavaScript file that executes after (important word) the Google AdSense script. Something like:

var ad = document.querySelector(".google-auto-placed"); //Can be replaced any identifying trait depending on the actual Ad Div
ad.innerHTML="";
<html>

<body>

  <div class="row">
    <div class="col-md-4">
      somecontent
    </div>
    <div class="google-auto-placed">
      ad content
    </div>
    <div class="col-md-4">
      somecontent
    </div>
    <div class="col-md-4">
      somecontent
    </div>

</body>

</html>

This removes the ad (if it is executed after the Google AdSense script). However, this may set of AdBlocker detectors.

Essentially what this does is it selects the google-auto-placed class using document.querySelector(); which will select a specific element depending on the prefix, . for class in this case. Sadly, this may not work with some older IE versions. If you have multiple elements you may want to check the parentElement to check if it is the correct ad. You can read about that here.

To read up more about document.querySelector() have a look here.

  • I forgot to mention that you should check the parent element to make sure you found the correct ad (or you could just figure out what number the ad is chronologically and just `ad[5].innerHTML="";` it, ie. if the ad was the 6th to select it you would select `ad[5]`). I will edit it for clarity now. –  Jul 05 '18 at 05:46
  • Yeah i can do that – Surya Neupane Jul 05 '18 at 05:48
  • 3
    Right, but isn't this against the Adsense TOS? – Bangkokian Feb 17 '20 at 12:45
1

If you don't want to see auto ads you can close it ("google-auto-placed" ads.) Just turn off auto ads in adsense page. Your unit ads still will be showing. https://support.google.com/adsense/answer/9214966?hl=en

Isa Ataseven
  • 166
  • 1
  • 10