Hugo博客添加Google AdSense

2023-11-11
#Blog

1. 步骤

  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 的账号

  1. 在主题文件夹 /layouts/_default/baseof.html 文件中的 <head>..</head>之间,加入:
{{ partial "ad.html" . }}

注意⚠️:第1步和第2步,主要是将script代码放入<head>..</head>中。

  1. 在博客目录static文件夹,创建 ads.txt文件,内容为:
google.com, pub-3168821395322381, DIRECT, f08c47fec0942fa0

2. 参考