Add Adsense Ads to Your Posts
This post sets out how you can add your Google Adsense code to your blog posts. As this is MakeWithHugo, we’ll be adding them to our Hugo site. You’ll need a few things before starting, an Adsense account, the snippet of code from Adsense and knowing where you want to put them (or auto ads for the easy option). There’s a few different ways to achieve this, based on where you want them.
Only Show HTML When on Local/Production
For Hugo Themes, you will sometimes want to act differently between you working on the site, developing it, and the site if it’s running publicly on the internet. One example of this is if you show advertisements - you don’t want them showing on local (and contributing to impressions) but you would want to show them to the world. The reverse is also true, you could load scripts like livereload only on local development, through hugo server.