[hugo]how to add google adsense in hugo post
add adsense-inarticle.html
in your partials
.
vim /your/hugo/theme/yourtheme/layout/partial/adsense-inarticle.html
add these:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- postPage -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="{{.Site.Params.Adsclient}}"
data-ad-slot="{{.Site.Params.AdsinArticleSlot}}"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
then go to your config.tomi
add Adsclient
& AdsinArticleSlot
in params
Adsclient = "ca-pub-0000000000"
AdsinArticleSlot = "00000000"
finally, add these code after .Content
in single.html
:
{{ partial "adsense-inarticle.html" . }}
look like this:
<article>{{ .Content | emojify }}{{ partial "adsense-inarticle.html" . }}`</article>