Hugo博客添加Google AdSense
1. 步骤
- 在
simple-style主题文件夹/layouts/partials/建立Google AdSense文件ad.html,内容为:
<!-- Google Adsense -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3168821395322381"
crossorigin="anonymous"></script>
注意⚠️: 3168821395322381 为 Google AdSense 的账号
- 在主题文件夹
/layouts/_default/的baseof.html文件中的<head>..</head>之间,加入:
{{ partial "ad.html" . }}
注意⚠️:第1步和第2步,主要是将script代码放入<head>..</head>中。
- 在博客目录
static文件夹,创建ads.txt文件,内容为:
google.com, pub-3168821395322381, DIRECT, f08c47fec0942fa0