Support » Fixing WordPress » Question regarding section targetting of Google Adsense

  • Folks – I discovered a new trick from Google Adsense which allows section specific ad targeting which (in theory) will make the content sensitive ads more relevant on your site.

    The article which discusses this is found at

    It involves using start/end HTML tags which Google will recognise (e.g. <!– google_ad_section_start –> and <!– google_ad_section_end –>)

    Now – I know I can manually code these into a post..but my question is this. If I want this to happen automatically for every post I do (to force google to look at the posts content)…which part of WordPress or my theme files do I need to modify? What would be the correct syntax and instruction to use to insert the above Start and end html tags at the appropriate points?

    Thanks in advance to all you WP gurus.


Viewing 10 replies - 1 through 10 (of 10 total)
  • First off, “I don’t know”
    but I would imagine that the index.php, post.php and page.php is what you need to edit. Add the code before and after the “content” portions of the file. I assume you want to weed out the sidebar info so putting this in the header/footer would be counter productive.

    I’ll look at the article because this sounds like a good idea. I’m sure someone could easily make a plugin for this too.

    Would have to go within the loop…. only thing is, how are you going to limit the number of displays? To remain within the TOS I mean….

    Within the loop, you could put it either at the top, just after

    <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?> or at the end, just before

    <?php endif; ?>.

    I just added it to my index.php just outside the loop. Thus, all my main page posts are within the target area leaving my header, footer, and both sidebars out.

    They say you can use it as much as you want so long as you’re not manipulating the ad results. So you could limit it to the actual post content (leaving out the title and comments etc. if you want)

    It would be nice if a plugin existed that added it to specific catagories so that it ignored the occasional “silly” post (there is an “ignore” option in the article too)

    Any chance you could post some code / examples here for those of us who are ‘challenged’ in that department? 😉

    Thanks in advance.


    This is my index.php

    <?php get_header(); ?>
    <!-- google_ad_section_start -->
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_meta_image(); ?>
    <div class="post">

    <?php the_date('','<h2>','</h2>'); ?>

    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>

    <span class="edit"><?php edit_post_link(__('edit this post')); ?></span>

    <div class="storycontent">
    <?php the_content(__('[ continued...]')); ?>

    <p class="meta">
    <?php if(is_page()) : ?>
    <a href="wp-print.php?page_id=<?=the_ID()?>" title="Printer Friendly Version">Print This Article</a>
    <?php else : ?>
    <a href="wp-print.php?p=<?=the_ID()?>" title="Printer Friendly Version">Print This Article</a>
    <?php endif; ?>

    <?php _e("posted to"); ?> <?php the_category(',') ?> @
    <a href="<?php the_permalink() ?>" title="<?php _e('link to ') ?><?php the_title() ?>"><?php the_time() ?></a>

    <p class="feedback">
    <?php wp_link_pages(); ?>
    <?php comments_popup_link(__('be the first to comment'), __('be the second to comment'), __('add to the % comments')); ?>

    <?php trackback_rdf(); ?>

    <?php comments_template(); // Get comments.php template ?>

    <!--end .post-->

    <?php endwhile; else: ?>
    <?php include (TEMPLATEPATH . '/errormessage.php'); ?>
    <?php endif; ?>

    <!-- google_ad_section_end -->

    <?php posts_nav_link('','','previous page') ?> |
    <a href="<?php echo get_bloginfo ('url') ?>"><?php _e ('home') ?></a> |
    <?php posts_nav_link('','next page','') ?>

    <?php get_footer(); ?>

    I added the start code right after the <get header> (which calls my left sidebar) and ended just before the <get footer> (which calls my right sidebar) This will include the date, post title and “make comments” in the adsense section but I figure my titles might be relevent. If you wanted to be more selective, I would put it like this…

    <!-- google_ad_section_start -->
    <div class="storycontent">
    <?php the_content(__('[ continued...]')); ?>
    <!-- google_ad_section_end -->

    This would keep it to just the post content of each displayed post (i.e. however many show on your main page)

    Excellent – thanks for that example. I’ve got it included in my index.php, although I’m still trying to figure out why ads only appear for the first 2 posts on my index page.


    hmm – did the above but I can’t say I’ve noticed any difference on the ‘targeting’ of adverts. Still looks the same to me.


    Retargetting can take a couple of days I understand.

    The article says up to 2 weeks.

    You can use section targeting to make suggestions about as many sections of a page as you like. However, please be aware that we can’t guarantee results, and that it may take up to 2 weeks before our crawlers take into account any changes you’ve made to your site.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Question regarding section targetting of Google Adsense’ is closed to new replies.