As a Tistory blogger, I recently encountered an issue where my ads were not displayed on my blog. After conducting some research and troubleshooting, I was able to find the solution.
The problem occurred after I changed my blog's skin to MaterialT Mark3. The error message appeared in Chrome's developer tools console:
adsbygoogle.push() error: No slot size for availableWidth=0 TagError
I tried searching for similar errors online and found that others had experienced this issue as well. The solution involved modifying the ad code to use window.onload
.
Here is the original code:
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
And here is the modified code:
<script>
window.onload = function() {
(adsbygoogle = window.adsbygoogle || []).push({});
}
</script>
The window.onload
event listener ensures that the ad code is executed only after the page has finished loading, which should resolve the issue.
However, I noticed that the bottom ads were not displayed. After further investigation, I found that the problem was with the ad slot size being set to 0. To fix this, I added the following code:
<script>
function Adcode() {
(adsbygoogle = window.adsbygoogle || []).push({});
}
var timeoutID;
$(function() {
timeoutID = window.setTimeout(Adcode, 1000);
})
</script>
This code waits for 1 second before executing the ad code. I added this code to my blog's header section, and it resolved the issue.
In some cases, ads may not display properly if there are multiple ads on a page. To resolve this issue, you can copy and paste the push
code into the line above and add an additional line:
<script>
(adsbygoogle = window.adsbygoogle || []).push({}); // Add this line to fix ad display issues
</script>
By implementing these solutions, I was able to successfully display ads on my Tistory blog.