Show AdSense Only on Post Pages

If your blog covers a variety of topics, the relevance of Google AdSense ads on the main/index page suffers as it tries to figure out what to display. To minimize this problem, you can restrict the ads to the post pages only where the content is more focused. Here’s how to do it on Blogger.

  1. Log into your blog
  2. Click the Template tab
  3. If you don’t already have an AdSense widget on your blog, add one on the Page Elements page
  4. Make a backup of your template by clicking on the Download Full Template link
  5. On the Edit HTML page, select the Expand Widget Templates checkbox
  6. Scroll down to about the bottom quarter of the template contents (the position will vary based on the template you’re using and number of widgets in your blog)
  7. Look for the following widget code (if you have more than one AdSense widget, there will be more than one of these code blocks, each with a different id)
    <b:widget id=’AdSense1′ locked=’false’ title=” type=’AdSense’>
    <b:includable id=’main’>
    <div class=’widget-content’>
    <data:adCode/>
    </div>
    </b:includable>
    </b:widget>
  8. Add the following <b:if> and </b:if> tags so that the widget looks like the one below
    <b:widget id=’AdSense1′ locked=’false’ title=” type=’AdSense’>
    <b:includable id=’main’>
    <b:if cond=’data:blog.pageType == “item”‘>
    <div class=’widget-content’>
    <data:adCode/>
    </div>
    </b:if>
    </b:includable>
    </b:widget>
  9. Repeat for any other ad widgets you have on your blog
  10. Save the template and then view your blog

The contents of the ad widget should now only appear when viewing an individual post.

Note that the Blogger help topic, Page Elements Tags for Layouts, indicates that a widget tag can have a pageType attribute that, when set to “item”, is supposed to display that widget only on post pages. However, it didn’t work for the AdSense widget. So, I added an if condition to the widget’s contents instead.

I’m not sure if pageType was intended not to work on the AdSense widget but, since this technique helps the relevance of the ads, hopefully no one will complain. If you know a better way to handle this or how to get the pageType attribute to work properly for this widget, leave a comment.