Hexo - Icarus 使用 Google AdSense

使用Hexo主題Icarus來架設網站,想要使用Google AdSense來增加廣告收益時,
搜尋網站資料,大多是使用Hexo的Next主題來架設。

經過一番研究之後,終於在自己的網站上嵌入Google AdSense了。
以下為嵌入Google AsSense的步驟。

只支援Icarus 3.0之前的版本

Step 1: 註冊Google AsSense帳號

申請前,網站內容需要先豐富,否則會申請不過。

首先先登入Google 帳號,並填入你的網站。

接下來就填入你的相關資料,以及驗證,完成註冊。

Step 2: 驗證網站

完成註冊後,Google需要驗證你的網站。

Google AdSense會給你一段Script ,將此Script放在/hexo/theme/hexo-theme-icarus/layout/layout.ejs的head之中

layout.ejs
1
2
3
4
5
6
7
<!DOCTYPE html>
<html <%- has_config('language') ? ' lang="' + get_config('language').substring(0, 2) + '"' : '' %>>
<head>
<%- _partial('common/head') %>
<script data-ad-client="ca-pub-xxxxxxxxxx" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</head>
<body> ... </body>

然後在Google AdSense上點擊驗證即可。

一般會在三天之內收到通知信,就可以得知是否通過Google AdSense的審核。

Step 3: 建立廣告

通過審核後,可在Google AdSense上建立廣告,在此我是使用「按廣告單元 - 多媒體廣告」來建立。

建立好之後,會得到一段Script

將此Script貼到你所想要的Widget中

Ex:

Footer : /hexo/theme/hexo-theme-icarus/layout/common/footer.ejs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<footer class="footer">
<div class="container">
<div class="level">
</div>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 橫式廣告 -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-xxxxxxxx"
data-ad-slot="xxxxxxx"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</footer>

Profile : /hexo/theme/hexo-theme-icarus/layout/widget/profile.ejs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<div class="card widget">
<div class="card-content">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 方形廣告 -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-xxxxxxxxx"
data-ad-slot="xxxxx"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>

Link : /hexo/theme/hexo-theme-icarus/layout/widget/link.ejs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<div class="card widget">
<div class="card-content">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 方形廣告 -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-xxxxxxxxx"
data-ad-slot="xxxxx"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>

大約過30分鐘後,就可以看到嵌入的廣告了。

作者

Nick Lin

發表於

2019-10-25

更新於

2023-01-18

許可協議


評論