Published on

Adding Google AdSense to Octopress

Authors

These are my notes from when I added Google AdSense to an Octopress blog.

Add ads to blog posts

There may be other ways to do it, but this time I edited the post template directly. Open the file below and modify it.

source/_layouts/post.html

<div>
<!-- Paste the ad code you want to show above the post here -->
<article class="hentry" role="article">
 .
 .
 .
</footer>
<!-- Paste the ad code you want to show below the post here -->
</div>
</article>

This time I placed the ad before the comments section, but you can change the insertion point as needed.

Show ads in the sidebar

For sidebar AdSense, first create a file like the following. Looking at the other files, it seems you only need to write the content you want to show inside a <section> tag.

/source/_include/custom/asides/google_adsense_300x250.html

<section>
  <!-- Paste the ad code here -->
</section>

Open _config.yaml and add the file name you just created to default_asides. Items written on the left side of the list are shown from top to bottom, so you can adjust the display order by rearranging them.

default_asides: [custom/asides/google-adsense_300x250.html, ...]

If you want to show a different AdSense unit as well, create another file in the same way and add it to _config.yaml.