0%

hexo landscape add google-adsense(hexo默认主题添加谷歌广告)

layout下新建文件(Goole内嵌广告代码)

cat themes/landscape/layout/google_adsense.ejs

1
2
3
4
5
6
7
8
9
10
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-NUMBER"
data-ad-slot="5598807232"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

NUMBER按需替换即可

新建page

hexo new page adsense

1
2
3
4
5
---
title: adsense
date: 2019-11-25 03:48:48
type : adsense
---

边栏展示广告

themes/landscape/_config.yml添加adsense

1
2
3
4
5
widgets:
- category
- archive
- recent_posts
- adsense

新建themes/landscape/layout/_widget/adsense.ejs

1
<%- partial('google_adsense.ejs') %>

文章内部展示广告

编辑themes/landscape/layout/_partial/article.ejs
建议放到正文后面

1
2
         <%- post.content %>
+ <%- partial('google_adsense.ejs') %>