After setting up my blog, I had suffered from the error message 'Uncaught TagError: adsbygoogle.push() error: All ins elements in the DOM with class=adsbygoogle already have ads in them.' for a long time, and the advertisements wouldn't appear. I couldn't find a solution no matter how much I searched Google, but suddenly I managed to solve the problem with the web knowledge I have, so I thought I'd share it.
When you create an ad unit in AdSense, you will be provided a code that looks similar to the following:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-{your_adSense_number}"
crossorigin="anonymous"></script>
<ins class="adsbygoogle"
style="display:block"
data-ad-format="fluid"
data-ad-layout-key="..."
data-ad-client="..."
data-ad-slot="..."></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
I created various ads and pasted them where needed, but the problem was that the following code was duplicated.
<script async='async' crossorigin='anonymous' src='https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-{your_adSense_number}'/>
Since both parts retrieve the same js file, I removed those parts and placed them only once in the head of the document. It resolved the problem very cleanly.
If anyone else is suffering from the same issue, I recommend trying this method.
0 개의 댓글:
Post a Comment