How do you use multiple adsense units on one page?

后端 未结 4 1610
野性不改
野性不改 2021-01-31 17:17

How do you have multiple adsense units on one website? The only code Google gives are per unit.



        
4条回答
  •  -上瘾入骨i
    2021-01-31 17:23

    To have more then one adsense unit on one page you must add more rows of (adsbygoogle = window.adsbygoogle || []).push({});.

    So if you have 3 ad units, you want to use it 3 times.

    (adsbygoogle = window.adsbygoogle || []).push({});
    (adsbygoogle = window.adsbygoogle || []).push({});
    (adsbygoogle = window.adsbygoogle || []).push({});
    

    If you want to do it dynamically, use this:

    [].forEach.call(document.querySelectorAll('.adsbygoogle'), function(){
        (adsbygoogle = window.adsbygoogle || []).push({});
    });
    

提交回复
热议问题