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>
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 just found an easier way to do this.
You should go :
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With