现在 Google Adsense 后台生成的广告单元代码默认都是完全异步的,因为它有助于改善网络延迟,为网站访问者提供更好的用户体验。不过有些博主站长有特殊要求需要生成同步广告代码,目前还可以通过后台获取代码的时候选择代码类型为“同步”就可以自动生成同步代码。具体如下图所示:
不过 Google Adsense 即将调整广告单元(详见『Google AdSense 的广告单元即将迎来 6 大变化』),届时我们就无法再在 AdSense 帐号中将广告代码类型更改为“同步”从而获得同步代码了。到那个时候,我们只能参考以下方法修改广告单元代码。
1、获取广告单元异步代码:
<script async src="//pagead2.googlesyndication.com/
pagead/js/adsbygoogle.js"></script>
<!-- leaderboard -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
2、将异步代码中的尺寸、data-ad-client 和 data-ad-slot 值填写到以下同步广告单元代码中相应的位置,其他代码不需要修改。
<script type="text/javascript">
google_ad_client = "ca-pub-xxxxxxxxxxxxxxxx";
google_ad_slot = "1234567890";
google_ad_width = 728;
google_ad_height = 90;
</script>
<!-- leaderboard -->
<script type="text/javascript"
src="//pagead2.googlesyndication.com/
pagead/show_ads.js">
</script>
答案内容整理自@Adsense 帮助